Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to delete json object using python?

#!/usr/bin/python                                                               

# Load the JSON module and use it to load your JSON file.                       
# I'm assuming that the JSON file contains a list of objects.                   
import json
obj  = json.load(open("file.json"))

# Iterate through the objects in the JSON and pop (remove)                      
# the obj once we find it.                                                      
for i in xrange(len(obj)):
    if obj[i]["ename"] == "mark":
        obj.pop(i)
        break

# Output the updated file with pretty JSON                                      
open("updated-file.json", "w").write(
    json.dumps(obj, sort_keys=True, indent=4, separators=(',', ': '))
)
Comment

PREVIOUS NEXT
Code Example
Python :: check tensor type tensorflow 
Python :: numpy sort array by another array 
Python :: title() function in python 
Python :: dense rank in pandas 
Python :: continual vs continuous 
Python :: keys in python 
Python :: python datetime module 
Python :: extract pdf with python 
Python :: tkinter text blurry 
Python :: python get desktop directory 
Python :: python remove spaces 
Python :: python replace char in string 
Python :: twitter bot python 
Python :: df col to dict 
Python :: python how to change back to the later directory 
Python :: show multiple plots python 
Python :: change column names with number pd dataframe 
Python :: pandas iterrows 
Python :: python requests response get text 
Python :: loop through a column in pandas 
Python :: isnumeric 
Python :: create column for year in dataframe python 
Python :: python __init_subclass__ 
Python :: python logging basicconfig stdout 
Python :: make tkinter label and input 
Python :: Current date and time or Python Datetime today 
Python :: read from text file and append in list 
Python :: opencv invert image 
Python :: check if host is reachable python 
Python :: repeat array along new axis 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =