i have a json variable like this
var jsondata={"all":"true"}
i want to push another key and value to the jsondata. after that my jsondata have to be like this.
{"all":"true","FDamount":"false","DDamount":"true"}
how to do that??? i tried jsondata.push({"FDamount":"false"}) and jsondata.push("FDamount:false"). both of these method is not working.
thank you
To add a new key value pair in existing JSON object using JavaScript, we can parse the JSON string with JSON. parse , then add the key-value pairs we want, and then convert the object back to a JSON string with JSON. stringify . to parse s into an object with JSON.
import json with open("your_json_file. txt", 'r') as f: data = json. loads(f. read()) #data becomes a dictionary #do things with data here data['ADDED_KEY'] = 'ADDED_VALUE' #and then just write the data back on the file with open("your_json_file.
A JSON object contains zero, one, or more key-value pairs, also called properties. The object is surrounded by curly braces {} . Every key-value pair is separated by a comma. The order of the key-value pair is irrelevant. A key-value pair consists of a key and a value, separated by a colon ( : ).
JSON objects are written in key/value pairs. JSON objects are surrounded by curly braces { } . Keys must be strings, and values must be a valid JSON data type (string, number, object, array, boolean or null). Keys and values are separated by a colon.
Like this
jsondata.FDamount = 'false'; // or jsondata['FDamount'] = 'false';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With