Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I am scraping the web and pulling the HTML attributes out as the dictionary and want to compile all of these as objects into the JSON file.

The dictionary is shown below:

{'car':'ford',

   'mpg':45,

   'VIN':'A31GAFD'}

and I want the JSON file to look like this:

{

    {'car':'ford',

   'mpg':45,

   'VIN':'A31GAFD'},

    {'car':'bmw',

   'mpg':12,

   'VIN':'B441GAFD'}

}

1 Answer

0 votes
by (36.8k points)

You outer object has to be an array rather than this:

[

    {

        'car':'ford',

        'mpg':45,

        'VIN':'A31GAFD'

    },

    {

        'car':'bmw',

        'mpg':12,

        'VIN':'B441GAFD'

    }

]

which is [ ... ] instead of { ... }

Do check out Data Science with Python course which helps you understand from scratch 

Browse Categories

...