How To Remove A Value From A Json Array?
path = os.path.dirname(os.path.realpath(__file__)) if os.path.exists(path + '/nomore.json'): blacklist = json.loads(open('%s/nomore.json' % (path)).read())
Solution 1:
Well... if blacklist
is your json, then why not do the following?
# If you know the value to be removed:
blacklist['blacklist'].remove(225915965769121792)
# Or if you know the index to be removed (pop takes an optional index, otherwise defaults to the last one):
blacklist['blacklist'].pop()
# Or
del blacklist['blacklist'][0] # 0 or any other valid index can be used.
Solution 2:
lst = [100, 200, 300, 400]
idx = lst.index(300)
removed_item = lst.pop(idx)
print(removed_item)
print(lst)
Post a Comment for "How To Remove A Value From A Json Array?"