Archive: NSJSON formatting issue


NSJSON formatting issue
Hi,

I am using nsjson plugin to modify Google chrome's preferences file.

I want to add a new field (urls_to_restore_on_startup) in the session node if it is not already present. But the new node added has faulty format which is corrupting the preferences file.
I am doing this:

 nsJSON::Set "session" "urls_to_restore_on_startup" /index 0 /Value '"http://www.nsis.sourceforge.net"' ;changing start page


It should result like this


Preferences.json
.
.
"session": {
"restore_on_startup": 4,
"restore_on_startup_migrated": true,
"urls_to_restore_on_startup": [ "http://www.nsis.sourceforge.net" ]
}

But instead it is like this : -

Preferences.bad
.
.
"session": {
"restore_on_startup": 4,
"restore_on_startup_migrated": true,
"urls_to_restore_on_startup":{
"http://www.nsis.sourceforge.net"
}
}


The curly braces are added here which are ruining everything.

How to get the right format ??

The value is itself parsed as JSON. If you want the value to be an array (i.e. in square brackets) then put square brackets in your value string. Also you don't need /index 0 in there (that is creating a new sub-node, hence the curly brackets).

I.e.

nsJSON::Set "session" "urls_to_restore_on_startup" /value '["http://www.nsis.sourceforge.net"]'
The example script demonstrates this and all other usage.

Stu

Oh great. This fixed it. Thanks. :)