Scott Scott - 2 months ago 12
JSON Question

how to print json data

I have following json file and python code and i need output example...

json file

{"b": [{"1": "add"},{"2": "act"}],
"p": [{"add": "added"},{"act": "acted"}],
"pp": [{"add": "added"},{"act": "acted"}],
"s": [{"add": "adds"},{"act": "acts"}],
"ing": [{"add": "adding"},{"act": "acting"}]}


python

import json
data = json.load(open('jsonfile.json'))
#print data


out put example

>> b
>> p
>> pp
>> s
>> ing


any ideas how to do that?

Answer

This doesn't have anything to do with JSON. You have a dictionary, and you want to print the keys, which you can do with data.keys().

Comments