Overview
Features
Download
Documentation
Community
Add-Ons & Services

JSONConfiguration

Please post support and help requests here.

JSONConfiguration

Postby rmoffer » 01 Mar 2012, 05:57

I see in the sandbox that there was the beginnings of a JSONConfiguration - but it doesn't look like there's enough there to work ?

Not so much for actual configuration files, but I like the idea of a JSON class that presents the same interface as the other configuration classes and their XPath like queries to both create and parse a JSON document.


Failing that, has anyone a recent recommendation for handling JSON data (input and output) in a (dynamic) Poco friendly manner ?

richard.
rmoffer
 
Posts: 48
Joined: 09 Feb 2009, 19:20
Location: San Francisco bay area.

Re: JSONConfiguration

Postby fbraem » 01 Mar 2012, 13:34

I'm currently working on JSON classes which use Poco. My parser was originally written with Coco/R, but then I found out that Poco has a StreamTokenizer, so I removed the Coco/R grammar and wrote a new parser based on StreamTokenizer.

I also wrote a simple query class that makes it possible to look for properties in a JSON structure. For example "person.children[0].name" will return the value of name from the first element of the array.

I'll try to add a JSONConfiguration class. It can't be difficult when using the Query class.

For now these JSON classes are hosted in the git repository of my mqweb project (version 0.0.6): http://mqweb.sourceforge.net

PS. There are JSON classes in Poco, but they are part of the commercial version.
Zumuta!, that's the way to do IT!
fbraem
 
Posts: 101
Joined: 11 Aug 2008, 22:47
Location: Belgium

Re: JSONConfiguration

Postby rmoffer » 01 Mar 2012, 18:19

I've looked through the MQWeb project before and was impressed.

I doubt people are familiar with the EUPL (I'm not) - and the link you have in license.txt appears broken, you might want to consider adding the actual text. However since according to Wikiepedia/OS Watch the EUPL is a strong copyleft so I can't go anywhere near it.

Didn't know that they'd added JSON support to the commercial remoting - that might be another option (but probably not cost effective since we've already developed our own SOAP server and clients).


richard.
rmoffer
 
Posts: 48
Joined: 09 Feb 2009, 19:20
Location: San Francisco bay area.

Re: JSONConfiguration

Postby guenter » 01 Mar 2012, 23:12

Last year we've added support for JSON-RPC to Remoting. As part of the JSON-RPC implementation I've written some classes for parsing JSON. In total, we now have four different JSON implementations written with POCO. Two of them are in the trunk/sandbox (Foundation - JSON support in DynamicAny/Var and Web library, written by Alex), Franky's implementation, and the one from Remoting. Every one has a different API, of course. Interestingly, I'm currently working on a project where a JSONConfiguration could be very useful as well. If we could use Franky's implementation, and add it to the Util library (IMO this is where it fits best), this would be great.
guenter
 
Posts: 1107
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: JSONConfiguration

Postby fbraem » 02 Mar 2012, 16:20

guenter wrote:If we could use Franky's implementation, and add it to the Util library (IMO this is where it fits best), this would be great.

I'd love to contribute my JSON classes to Poco. I'll change the structure on my mqweb project so that the classes can be easily integrated into Util library and I'll change the license of these classes to the same license of Poco. And I'll add more tests to the testsuite. In the meantime, if you can't wait for the Poco integration, you can already start to use the classes from mqweb.

Note: The EUPL license can now be found here: http://joinup.ec.europa.eu/software/page/eupl
Zumuta!, that's the way to do IT!
fbraem
 
Posts: 101
Joined: 11 Aug 2008, 22:47
Location: Belgium

Re: JSONConfiguration

Postby fbraem » 12 Mar 2012, 22:01

The JSON classes are now available in the repository of my MQWeb project:

MQWeb JSON project
Zumuta!, that's the way to do IT!
fbraem
 
Posts: 101
Joined: 11 Aug 2008, 22:47
Location: Belgium

Re: JSONConfiguration

Postby rmoffer » 14 Mar 2012, 18:09

Thanks for posting the code.


The JSONConfiguration appears to have two methods missing when compared with the XMLConfiguration (or at least I'm trying to use two methods that aren't there).

Code: Select all
save( std::ostream)
loadEmpty( std::string )



thanks again,

richard.
rmoffer
 
Posts: 48
Joined: 09 Feb 2009, 19:20
Location: San Francisco bay area.

Re: JSONConfiguration

Postby fbraem » 14 Mar 2012, 19:31

rmoffer wrote:
Code: Select all
save( std::ostream)
loadEmpty( std::string )


richard.


These two methods are added.

Franky
Zumuta!, that's the way to do IT!
fbraem
 
Posts: 101
Joined: 11 Aug 2008, 22:47
Location: Belgium

Re: JSONConfiguration

Postby rmoffer » 15 Mar 2012, 04:57

Thanks Franky.

Are there any known limitations - i.e. unsupported JSON features - such as nested objects ?

I'm not yet sure what's going on in my initial work but its not working as a drop in replacement for the existing XMLConfiguration. I'll be looking at it some more tomorrow. I don't need it to be a drop in replacement so it might just be how I use the keys that is tripping me up...

(For those interested I'm using the XMLConfiguration and JSONConfiguration to generate XML and JSON views of a C++ data structure (Protocol Buffer) - I'm building this up dynamically by traversing the C++ object and calling the equivalent of cfg->setString("fred.henry.george", "hello").

Then at the end I just write the XMLConfiguration and JSONConfiguration objects over the wire.
rmoffer
 
Posts: 48
Joined: 09 Feb 2009, 19:20
Location: San Francisco bay area.

Re: JSONConfiguration

Postby rmoffer » 15 Mar 2012, 19:29

Franky,

A bit more info...

My test case

Code: Select all
  void JSONTest::testConfiguration2()
  {
    Poco::Util::JSONConfiguration config;

    std::string json = "{ \"config\" : "
                        " { \"prop1\" : \"value1\", "
                           " \"prop2\" : 10, "
                           " \"prop3\" : [ \"element1\", \"element2\" ], "
                          " \"prop4\" : { \"prop5\" : false, "
                                        " \"prop6\" : null } "
                                        "}"
                       "}";

    std::stringstream ss;
    try
    {
      config.loadEmpty("config");

      config.setString( "config.prop1", "value1");
      config.setInt( "config.prop2", 10);
      config.setString( "config.prop3[0]", "element1");
      config.setString( "config.prop3[1]", "element2");
      config.setBool( "config.prop4.prop5", false);

      config.save(ss);

      std::cout << std::endl << ss.str() << std::endl;

      assert( ss.str() == json );
    }
    catch(Poco::Util::JSONException jsone)
    {
      std::cout << jsone.message() << std::endl;
      assert(false);
    }

    std::string property1 = config.getString("config.prop1");
    assert(property1.compare("value1") == 0);

    int property2 = config.getInt("config.prop2");
    assert(property2 == 10);

    int nonExistingProperty = config.getInt("config.prop7", 5);
    assert(nonExistingProperty == 5);

    std::string arrProperty = config.getString("config.prop3[1]");
    assert(arrProperty.compare("element2") == 0);

    bool property35 = config.getBool("config.prop4.prop5");
    assert(! property35);

    try
    {
      config.getString("propertyUnknown");
      assert(true);
    }
    catch(Poco::NotFoundException nfe)
    {
    }

  }




Produces the following output

Code: Select all
{
  "config" : {
    "prop1" : "value1",
    "prop2" : "10",
    "prop3[0]" : "element1",
    "prop3[1]" : "element2"
  },
  "prop5" : "false"
}



The issues as I see it

  • should prop2's value be in quotes ? (it was added with setInt() )
  • no array for prop3
  • prop5 is not an element of prop4 (doesn't exist)
  • prop5's value shouldn't be in quotes.
  • the loadEmpty("config") / setString("config.*") doesn't seem to match with the XMLConfiguration's use of loadEmpty() - I don't think its an issue with me - but it does arguably lead to having different keys in the set* methods between the XMLConfiguration and JSONConfiguration

By goal is to programmatically construct the JSON document that's in the test case.


Thanks

richard.
rmoffer
 
Posts: 48
Joined: 09 Feb 2009, 19:20
Location: San Francisco bay area.

Next

Return to Support

Who is online

Users browsing this forum: No registered users and 4 guests

cron