I’m having a little trouble with some JS and hope someone can help.
I have two JSON strings that are collected via AJAX using jQuery and then parsed accordingly. The issue I have is that if I ever want to add new features to the application I am making, the JSON strings are statically stored in the database and don’t change if new attributes are added to the default JSON string.
var string1 = {
"col1": [
{
"foo": "bar"
}
],
"col2": [
{
"foo": "bar",
"bar": "foo"
}
],
"col3": [
{
"foo": "bar"
}
]
}
var string2 = {
"col1": [
{
"foo": "bar"
}
],
"col2": [
{
"foo": "bar"
}
]
}
string2 is the user saved the script, hypothetically saved three days ago. Since then, the default string string1 has been added to, and the information needs to be added to string2.
Can anyone help with this?
This will do:
Output:
jQuery JSON parser:
If you want to use jQuery parser or need support for IE7 you can replace
with
Unfortunately, jQuery cannot convert
json_objectback to JSON string, you will need another plugin or library for that.More on topic:
MDN documentation
Browser support