0
Q:

python create json object


  import json

# some JSON:
x =  '{ "name":"John", "age":30, "city":"New 
  York"}'

# parse x:
y = json.loads(x)
1
#import the json module
import json 

#create a dictionary which we can add to a json file
dictionary ={ 
    "name" : "sathiyajith", 
    "rollno" : 56, 
    "cgpa" : 8.6, 
    "phonenumber" : "9976770500"
} 

#open an object with following inputs: 'name_of_file.json', 'w'
#dump the content fromt he dictionary into the outfile
with open("sample.json", "w") as outfile: 
    json.dump(dictionary, outfile) 
0
import json

x = {
  "name": 
  "John",
  "age": 30,
  "city": "New York"
}

y = json.dumps(x)
0

example={
    "Playlists": [
        "Default"
    ],
    "Default": [
        "Resources\\Media\\C.mp3",
        "Resources\\Media\\K.mp3"
    ]
}
import json
json_file_path=input('Enter the path: ')
with open(json_file_path,'w') as hand:
     json.dumps(example,hand,indent=4) 
'''# dict,file_pointer,indentation'''
    
0

New to Communities?

Join the community