Answers for "generate json file python"

4

how to create json file in python

#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)
Posted by: Guest on November-20-2020
2

save json to file

import json

data = {}

with open('data.txt', 'w') as outfile:
    json.dump(data, outfile)
Posted by: Guest on February-27-2020
1

generate json in python

# JSON objects and JSON string objects can be created by reading a file directly 
# with the json.load() and json.dump() functions.

data_set = {"key1": [1, 2, 3], "key2": [4, 5, 6]}

json_dump = json.dumps(data_set)

print(json_dump)

# String of JSON object

OUTPUT
{"key1": [1, 2, 3], "key2": [4, 5, 6]}

json_object = json.loads(json_dump)

print(json_object["key1"])

# JSON object

OUTPUT
[1, 2, 3]
Posted by: Guest on July-05-2021
0

create json file in python

def check_splcharacter(test):
    # Make own character set and pass 
    # this as argument in compile method
 
    string_check= re.compile('[@_!#$%^&*()<>?/|}{~:]')
 
    # Pass the string in search 
    # method of regex object.
 
    if(string_check.search(test) == None):
        print("String does not contain Special Characters.") 
    else: 
        print("String contains Special Characters.")
Posted by: Guest on June-10-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language