A simple example of Python manipulating json data
- 2020-04-02 13:37:33
- OfStack
For more information, see the json documentation inside python:
python
>
>
>
Help (json)
Or the official document: http://docs.python.org/library/json.html#module-json.
Here's a simple example of parsing json using python:
#!/usr/bin/python
import json
#Function:Analyze json script
#Json is a script can descript data structure as xml,
#for detail, please refer to "http://json.org/json-zh.html".
#Note:
#1.Also, if you write json script from python,
#you should use dump instead of load. pleaser refer to "help(json)".
#json file:
#The file content of temp.json is:
#{
# "name":"00_sample_case1",
# "description":"an example."
#}
#f = file("temp.json");
#s = json.load(f)
#print s
#f.close
#json string:
s = json.loads('{"name":"test", "type":{"name":"seq", "parameter":["1", "2"]}}')
print s
print s.keys()
print s["name"]
print s["type"]["name"]
print s["type"]["parameter"][1]
PS: about json operation, here again for you to recommend a few more practical json online tools for your reference:
Online JSON code verification, verification, beautification, formatting tools:
(link: http://tools.jb51.net/code/json)
JSON online formatting tool:
(link: http://tools.jb51.net/code/jsonformat)
Online XML/JSON interconversion tool:
(link: http://tools.jb51.net/code/xmljson)
Json code online formatting/beautification/compression/editing/conversion tools:
(link: http://tools.jb51.net/code/jsoncodeformat)
Online json compression/escape tool:
(link: http://tools.jb51.net/code/json_yasuo_trans)
C language style /HTML/CSS/json code format beautification tool:
(link: http://tools.jb51.net/code/ccode_html_css_json)