Page 1 of 1

wxCrafter + JSON

Posted: Sat Dec 15, 2012 1:47 pm
by SlimFast
Just to let you know: I am working with wxCrafter as it is now several weeks and saying nothing means I didn't find any more major annoyances other those already said. I am looking forward to see AUI support - thats something I was missing personally.

BTW, I also have a personal question: In one of my projects I need to persist a configuration that changes a lot during runtime. Of course I thought about XML, but seeing all the JSON work in wxCrafter I wonder why you preferred JSON over XML. Is there a particular reason for it (more flexibility, easier API...) or is it a matter of taste? I am asking because I don't have strong experience with both: XML and JSON... well more with XML but none with JSON. :-) So for me it would still be OK to jump on the JSON train... I am coming from Oracle/SQL databases... but the config needs to be human readable this time.

Re: wxCrafter + JSON

Posted: Sat Dec 15, 2012 6:57 pm
by eranif
SlimFast wrote:Just to let you know: I am working with wxCrafter as it is now several weeks and saying nothing means I didn't find any more major annoyances other those already said. I am looking forward to see AUI support - thats something I was missing personally.
It is already implemented along with long list of new controls ... I am at the final stage of releasing a new version (non BETA)
SlimFast wrote:Of course I thought about XML, but seeing all the JSON work in wxCrafter I wonder why you preferred JSON over XML. Is there a particular reason for it (more flexibility, easier API...) or is it a matter of taste? I am asking because I don't have strong experience with both: XML and JSON... well more with XML but none with JSON
Theses days, JSON is IN, XML is out (you can see how all the major companies like Google, Facebook etc have moved to use JSON for their WebAPI). Also, I find it more readable and taking less diskspace

For example, a list of string saved in JSON format will be kept like this:

Code: Select all

["orange","apple","banana"]
While in XML you will need something like:

Code: Select all

<array><item>apple</item><item>apple</item><item>banana</item>
I created a very easy API based on cJSON (codelite is also slowly moving to JSON) which can be found here:

Code: Select all

https://sourceforge.net/apps/trac/codelite/browser/trunk/Plugin/json_node.cpp
here is an example of using this API:

Code: Select all

JSONRoot root(cJSON_Object); // Create a cJSON object root, there other forms of ctors that allow passing file name to parse or to create an array
root.toElement().addProperty("name", "my-name");
root.toElement().addProperty("last-name", "this is my last name");
printf("%s\n", toElement().format().mb_str(wxConvUTF8).data());
The output will be:

Code: Select all

{ "name" : "my-name", "last-name": "this is my last name" }
Also, it parses files *much* faster than wxWidgets XML classes
Eran

Re: wxCrafter + JSON

Posted: Sun Dec 16, 2012 2:49 pm
by SlimFast
eranif wrote:It is already implemented along with long list of new controls ... I am at the final stage of releasing a new version (non BETA)
Oh, that sounds sweeeeet! 8-)
eranif wrote:Theses days, JSON is IN, XML is out [...]
OK, thanks for the explanation and satisfying my curiosity (and sorry for being a little off-topic).