-4

[{"sku":43900,"name":"Batteries (4-Pack)","type":"HardGood","category": [{"id":"pc5","name":"Housewares"}]]

this is in json file. i want to load this and make a dictionary in Python from this input.i tired to load but confused how to create dictionary from this input.

import json
data = []
json_file=open ('prod.json')
json_str=json_file.read()
json_data=json.loads(json_str)
for items in json_data:
   print(items['name'])

1 Answers1

1
import json
s = '[{"sku":43900,"name":"Batteries (4-Pack)","type":"HardGood","category": [{"id":"pc5","name":"Housewares"}]}]'
list_of_dicts = json.loads(s)

Your json was invalid; I added a } in the right place.

Danielle M.
  • 3,607
  • 1
  • 14
  • 31
  • Thanks for your reply. Actually i am looking for more. I have hundreds of row like this. How to parse the data without typing every time all the Values in dictionary format. – Montreal_boy Oct 24 '18 at 23:20