Skip to content
⌘ NSIS Forum Archive

Modify json file without affecting other nodes and values of it

5 posts

meoit#

Modify json file without affecting other nodes and values of it

This is content of json file which I want modify.


{
"node1": {
"node11": {
"node121": {
},
"node122": {
"a1": true,
"a2": {
"a21": [
"a211",
"a212",
"a213"
],
"a22": [
"a221",
"a222"
],
"a23": [],
"a24": [
"a241",
"a242",
"a243",
a244"
]
},
"a3": {},
"a4": []
},
"node23": {
},
"node24": {
},
"node25": {
}
}
},
"node2": [],
"node3": {
"node31": {
"node311": {
"a3111": "xxx"
},
"node312": {
"a3121": "yyy"
},
"node313": {
"node3131": {
"a31311": "1",
"a31312": "2",
"a31313": "zzz",
}
}
},
"node21": "a211"
}
}
So, I need change values of node122 to {}, and change value of a31313 to Z1Z1Z1

And I do not understand example of nsJSON plugin.

Would you play with me in this case ?.
meoit#
nsJSON::set 'node1' 'node122' /value '{}' /file 'D:\Test\Test.json'

nsJSON::set 'node3' 'node313' 'a31313' /value 'Z1Z1Z1' /file 'D:\Test\Test.json'

nsJSON::Serialize /file 'D:\Test\Test.json'

But it is not as I need.
Anders#
The plug-in does not like empty objects.

nsJSON::Set /file "$%TEMP%\test.txt"
${IfThen} ${Errors} ${|} MessageBox mb_ok Err ${|}
nsJSON:😁elete 'node1' 'node122' /end
nsJSON::Set 'node1' 'node122' /value '{deleteme:0}'
nsJSON:😁elete 'node1' 'node122' 'deleteme' /end
nsJSON::Set node3 node31 node313 node3131 a31313 /value "Z1Z1Z1"
nsJSON::Serialize /format /file "$%TEMP%\test.txt"
You will not be able to read this again into the plug-in.
meoit#
Thanks Anders.

It is also remove all node existing other.

Content in test.txt:

{
"node1": {
"node122": {

}
},
"node3": {
"node31": {
"node313": {
"node3131": {
"a31313": "Z1Z1Z1"
}
}
}
}
}
How to keep nodes existing ?. (Keeping the content of other nodes, not affecting them, just manipulating the node we need to change.)