nsJSON plug-in
A JSON (JavaScript Object Notation) parser, manipulator and generator plug-in for NSIS. See the readme file for usage and more information.
http://nsis.sf.net/File:NsJSON.zip
Stu
Archive: nsJSON plug-in
nsJSON plug-in
A JSON (JavaScript Object Notation) parser, manipulator and generator plug-in for NSIS. See the readme file for usage and more information.
http://nsis.sf.net/File:NsJSON.zip
Stu
Nice work!
Please write a short article into wiki (or copy from readme): http://nsis.sourceforge.net/NsJSON_plug-in
very nice, especially since none of the xml plugins worked to my satisfaction and i got the option to use json files for the same purpose. thanks stu!
can i use it to parse json backup files from firefox (bookmark backup file/places)?
If it is valid JSON then yes.
Stu
New version:
1.0.0.1 - 1st July 2012I've tested this version on Chrome's Preferences JSON file.
* Fixed parsing of single digit numbers.
* Fixed Serialize not writing the output file when the stack isn't empty.
New version:
1.0.0.2 - 15th August 2012Note the Unicode build still expects ASCII encoded JSON files at the moment. I will perhaps add support for UTF-8 encoded JSON in the future.
* Fixed Unicode build parsing and serializing.
Hey Stu, is it possible to parse floating numbers with comma instead of point?
Some currencies use it: "1.23" is "1,23"
You have to wrap the value in quotes so that it will be treated as a string rather than a float. It is not possible any other way as a comma is used as the delimiter between objects and values (whitespace is ignored).
Stu
New version (with a fair number of changes):
1.0.1.0 - 28th August 2012http://nsis.sourceforge.net/File:NsJSON.zip
* Added /unicode switch to the Serialize function. Output files for both plug-in builds are now encoded in ANSI by default.
* Removed the Parse function in favour of Set /file [/unicode].
* Added /type, /key, /exists, /count, /isempty to the Get function.
* Added /index switch for referencing nodes by index.
Awesome plugin Stu. Any chance of extending it to support multiple json instances open at once?
That is already supported kind of. You just need to use Set /file with a node path to load a JSON file into. The only thing you cannot do is serialize a specific node to a file, which is where a change would be necessary. How much do you need multiple instance support (give an example of usage)?
Stu
I'm using in-memory json to store lots of my own user-specific data rather than tons of global variables.
Then I want to open up a program's settings file which is also in json, add a value and resave that settings.json.
It's also useful to separate different blocks of data and only serialize the parts I need during debug.
I guess the only thing that's really needed is the ability to serialize a specific node.
Unless I can find a better solution for my in-memory storage... Actually, thinking about it I could probably use your arrays plugin and do arrays of pointers to arrays using a counter or concatenating names like
CarPark0 = array of license plates (e.g. 0=ABC123, 1=DEF456, 2=GHI789)
CarPark0_ABC123 = array of that particular car's properties (e.g. Make=ShinyThingsInc, Color=Green)
So yeah, it probably isn't necessary to have the json plugin handle more than 1 root json object at a time. I'll just write my own serializer for the arrays.
Cheers again for your awesome stuff.
I am getting truncated string values when they have spaces:
nsJSON::Set `more_stuff` `PSCHED_009_NAME` /value `QoS Packet Scheduler`
Results in:
"more_stuff": { "PSCHED_009_NAME": QoS }
Values are parsed as JSON. If you want quoted strings you must use double quotes around the value:
nsJSON::Set `more_stuff` `PSCHED_009_NAME` /value `"QoS Packet Scheduler"`
Stu