I have a JSON variable that looks like this:
{"events": [
{"event_id": "1", "event_name": "Breakfast"},
{"event_id": "1", "event_name": "Calling Bob"}
]};
I have two vaiables
x=2; y=jam;
I want to push variables in json so x is event_id and y is event_name, so my json will look like
{"events": [
{"event_id": "1", "event_name": "Breakfast"},
{"event_id": "1", "event_name": "Calling Bob"},
{"event_id": "2", "event_name": "jam"}
]};
iam function used to click,
k='({"event_id":"'+x+'","event_name":"'+y+'"})';
san.events.push(k);
where san is the variable i kept json in. iam parses the san variable and applies a push action and builds and displays it, but as a result, the syntax of the json syntax changes, since additional "/" characters are generated in json.
source
share