convert python to json code example
Example 1: list to json python
import json
friends_list = [
'John','Rambo','Sam',
]
json_format = json.dumps(friends_list)
print(json_format)
print(type(json_format))
#PYTHON OUTPUT
["John", "Rambo", "Sam"]
<class 'str'>
Example 2: json.dumps python
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'''