Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

write json to file python

# to write on file
# data_dict is a dictionary

import json
        
with open('data.json', 'w') as f:
	json.dump(data_dict, f)
Comment

write to json file python

# Python program to write JSON
# to a file
  
  
import json
  
# Data to be written
dictionary ={
    "name" : "sathiyajith",
    "rollno" : 56,
    "cgpa" : 8.6,
    "phonenumber" : "9976770500"
}
  
with open("sample.json", "w") as outfile:
    json.dump(dictionary, outfile)
Comment

write json pythonb

import json

with open('data.txt') as json_file:
    data = json.load(json_file)
    for p in data['people']:
        print('Name: ' + p['name'])
        print('Website: ' + p['website'])
        print('From: ' + p['from'])
        print('')
Comment

write json pythonb

>>> import json
>>> data = {'item': 'Beer', 'cost':'£4.00'}
>>> jstr = json.dumps(data, indent=4)
>>> print(jstr)
{
    "item": "Beer",
    "cost": "u00a34.00"
}
Comment

write json pythonb

>>> jstr = json.dumps(data, ensure_ascii=False, indent=4)
>>> print(jstr)
{
    "item": "Beer",
    "cost": "£4.00"
}
Comment

write json pythonb

>>> import json
>>> data = {'people':[{'name': 'Scott', 'website': 'stackabuse.com', 'from': 'Nebraska'}]}
>>> json.dumps(data, indent=4)
{
    "people": [
        {
            "website": "stackabuse.com", 
            "from": "Nebraska", 
            "name": "Scott"
        }
    ]
}
Comment

PREVIOUS NEXT
Code Example
Python :: python pathlib create directory if not exists 
Python :: no module named pyinstaller 
Python :: selenium firefox webdriver 
Python :: send telegram bot message python 
Python :: apply lambda with if 
Python :: convert 1 to "one" python 
Python :: combine dataframes with two matching columns 
Python :: pandas data profiling 
Python :: input python 
Python :: python socket recv set timeout 
Python :: django view 
Python :: check remote port is open or not using python 
Python :: ravel python 
Python :: pdf to csv python 
Python :: python program to add two numbers using function 
Python :: WebDriverWait 
Python :: python update 
Python :: get all subsets of a list python 
Python :: python program to find largest number in a list 
Python :: np where nan 
Python :: python lists as dataframe rows 
Python :: pandas column filter 
Python :: write binary file in python 
Python :: python custom sort 
Python :: python one line if statement without else 
Python :: How to take total count of words in the list python 
Python :: ping from python 
Python :: intersection() Function of sets in python 
Python :: python binary string to int 
Python :: rest_auth pip 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =