Overview
Features
Download
Documentation
Community
Add-Ons & Services

JSONGenerator

General discussion regarding the development of POCO for contributors.

JSONGenerator

Postby fabioang » 10 Oct 2013, 16:37

Hi,

Any interest in a class to generate JSON object as stream ?
Code: Select all
    std::ostringstream oss;
    JSONGenerator jg(oss);
       
    jg.writeObject()                         // {
        .write("name", "Jane Doe")           //    "name":"Jane Doe",
        .writeObject("address")              //    "address":{
            .write("type", 1)                //        "type":1,
            .write("street", "1 A Street")   //        "street":"1 A Street",
            .write("city","null")            //        "city":null,
            .write("verified", false)        //        "verified":false
        .writeEnd()                          //    },
        .writeArray("phone-numbers")         //    "phone-numbers":[
            .writeObject()                   //        {
                .write("number", "555-1111") //            "number":"555-1111",
                .write("extension", "123")   //            "extension":"123"
            .writeEnd()                      //        },
            .writeObject()                   //        {
                .write("number", "555-2222") //            "number":"555-2222",
                .write("extension","null")   //            "extension":null
            .writeEnd()                      //        }
        .writeEnd()                          //    ]
    .writeEnd();                             // }
 
    std::cout << oss.str().c_str();


Thanks
Fabio
fabioang
 
Posts: 1
Joined: 10 Oct 2013, 16:34

Re: JSONGenerator

Postby guenter » 12 Oct 2013, 10:34

Looks useful. This could be integrated into the JSON library. Could you send a pull request?
guenter
 
Posts: 1129
Joined: 11 Jul 2006, 16:27
Location: Austria


Return to Contributors

Who is online

Users browsing this forum: No registered users and 1 guest