JSON Python JSON
Parse JSON
JSON (JavaScript Object Notation JavaScript) . - . JSON Python?
, json.loads()
json.load()
( ) JSON.
JSON
JSON, . JSON . JSON JavaScript -.
JSON :
{ "organization": "Company 1", "website": "https://www.website.org/", "formed": 2014, "certifications": [ { "name": "Responsive Web Design", "courses": [ "HTML", "CSS" ] }, { "name": "JavaScript Algorithms and Data Structures", "courses": [ "JavaScript" ] }, { "name": "Front End Development Libraries", "courses": [ "Bootstrap", "jQuery", "Sass", "React", "Redux" ] }, { "name": "Data Visualization", "courses": [ "D3" ] }, { "name": "Relational Database Course", "courses": [ "Linux", "SQL", "PostgreSQL", "Bash Scripting", "Git and GitHub", "Nano" ] }, { "name": "Back End Development and APIs", "courses": [ "MongoDB", "Express", "Node", "NPM" ] }, { "name": "Quality Assurance", "courses": [ "Testing with Chai", "Express", "Node" ] }, { "name": "Scientific Computing with Python", "courses": [ "Python" ] }, { "name": "Data Analysis with Python", "courses": [ "Numpy", "Pandas", "Matplotlib", "Seaborn" ] }, { "name": "Information Security", "courses": [ "HelmetJS" ] }, { "name": "Machine Learning with Python", "courses": [ "Machine Learning", "TensorFlow" ] } ] }
JSON Python
Python , JSON. json
.
import json
JSON, , json.loads()
.
import json # assigns a JSON string to a variable called jess jess = '{"name": "Jessica Wilkins", "hobbies": ["music", "watching TV", "hanging out with friends"]}' # parses the data and assigns it to a variable called jess_dict jess_dict = json.loads(jess) # Printed output: {"name": "Jessica Wilkins", "hobbies": ["music", "watching TV", "hanging out with friends"]} print(jess_dict)
JSON Python
JSON fcc.json
, , , , .
, Python open()
. with
, , .
with open('fcc.json', 'r') as fcc_file:
, OSError
. "FileNotFoundError"
fcc.json
.

, json.load()
fcc_data
.
fcc_data = json.load(fcc_file)
.
print(fcc_data)
:
import json with open('fcc.json', 'r') as fcc_file: fcc_data = json.load(fcc_file) print(fcc_data)
JSON Python
, , , JSON .

. , json.dumps()
indent
().
4 .
print(json.dumps(fcc_data, indent=4))

, sort_keys
True
.
print(json.dumps(fcc_data, indent=4, sort_keys=True))

JSON , - .
JSON, , json.loads()
.
JSON, , json.load()
.