Skip to content
Advertisement

How to create a JSON file from SQL query?

I am creating a JSON file from a SQL query. But I could not create truly. The problem is there is a “items” object and it has products. But mine create products directly not in “items” objects.

The Code.

JavaScript

yields the following JSON object as a result

JavaScript

while the desired one should be as follows

JavaScript

Advertisement

Answer

define objects_list as a dictionary instead of a list.

JavaScript

And append to the objects_list["items"].

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement