I'am having some problems with boost json in c++












0















I see that have a lot of questions very similar to mine, but I don´t see any solutions that fit with my problem.



I' am trying to create a JSON with boost library with the below structure:



{
"event_date": "2018-06-11T09:35:48.867Z",
"event_log": "2018-06-11 09:35:43,253 - recycler [TRACE]: Running recycler::WITHDRAW",
"cassettes": [
{
"value" : "0",
"currency": "BRL",
"CDMType" : "WFS_CDM_TYPEREJECTCASSETTE",
"lppPhysical" : [
{
"positionName" : "BIN1A",
"count" : "3"
}
]
},
{.....},{.....}
]
}


Below we will have the code that I have now:



boost::property_tree::ptree children, children2, child, child1, child2, child3, child4, child5, cassettes;

child1.put("value", "cash_unit->ulValues");
child2.put("currency", "std::string(cash_unit->cCurrencyID).substr(0, 3)");
child3.put("CDMType", "cash_unit->usType");

child4.put("lppPhysical.positionName", "ph_unit->lpPhysicalPositionName");
child5.put("lppPhysical.count", "cash_unit->ulCount");

cassettes.put("event_date", "2018-06-11T09:35:48.867Z");
cassettes.put("event_log", "2018-06-11 09:35:43,253 - recycler [TRACE]: Running recycler::WITHDRAW");

children.push_back(std::make_pair("", child1));
children.push_back(std::make_pair("", child2));
children.push_back(std::make_pair("", child3));

children2.push_back(std::make_pair("", child4));
children2.push_back(std::make_pair("", child5));

cassettes.add_child("cassettes", children);

write_json("C:\Temp\test.json", cassettes);`


Summarizing, I'm having difficulties to put an array of objects inside of an array of objects.










share|improve this question

























  • Hi Allan Paz, from your question, it is not clear what the problem is; could you specify what goes wrong? (error message, wrong output...) so it is easier for other people to answer your question?

    – Silmathoron
    Nov 21 '18 at 19:31











  • Sure, I'm having difficulties to insert an array (the lppPhysical) inside the cassettes (array of objects) like the above structure. My code only inserts the IppPhysical as an object in the cassettes.

    – Allan Paz
    Nov 22 '18 at 12:24











  • This is still unclear... Am I then correct in assuming that the structure you posted is your current output and that it is not what you want? If so could you please post the desired output?

    – Silmathoron
    Nov 22 '18 at 13:40











  • The mentioned structure is the correct one(mock), I need to translate this structure using boost library, but I am having difficulties on the lppPhysical part(Insert an array of objects as a child of the cassettes, which is an array of objects.

    – Allan Paz
    Nov 22 '18 at 13:50
















0















I see that have a lot of questions very similar to mine, but I don´t see any solutions that fit with my problem.



I' am trying to create a JSON with boost library with the below structure:



{
"event_date": "2018-06-11T09:35:48.867Z",
"event_log": "2018-06-11 09:35:43,253 - recycler [TRACE]: Running recycler::WITHDRAW",
"cassettes": [
{
"value" : "0",
"currency": "BRL",
"CDMType" : "WFS_CDM_TYPEREJECTCASSETTE",
"lppPhysical" : [
{
"positionName" : "BIN1A",
"count" : "3"
}
]
},
{.....},{.....}
]
}


Below we will have the code that I have now:



boost::property_tree::ptree children, children2, child, child1, child2, child3, child4, child5, cassettes;

child1.put("value", "cash_unit->ulValues");
child2.put("currency", "std::string(cash_unit->cCurrencyID).substr(0, 3)");
child3.put("CDMType", "cash_unit->usType");

child4.put("lppPhysical.positionName", "ph_unit->lpPhysicalPositionName");
child5.put("lppPhysical.count", "cash_unit->ulCount");

cassettes.put("event_date", "2018-06-11T09:35:48.867Z");
cassettes.put("event_log", "2018-06-11 09:35:43,253 - recycler [TRACE]: Running recycler::WITHDRAW");

children.push_back(std::make_pair("", child1));
children.push_back(std::make_pair("", child2));
children.push_back(std::make_pair("", child3));

children2.push_back(std::make_pair("", child4));
children2.push_back(std::make_pair("", child5));

cassettes.add_child("cassettes", children);

write_json("C:\Temp\test.json", cassettes);`


Summarizing, I'm having difficulties to put an array of objects inside of an array of objects.










share|improve this question

























  • Hi Allan Paz, from your question, it is not clear what the problem is; could you specify what goes wrong? (error message, wrong output...) so it is easier for other people to answer your question?

    – Silmathoron
    Nov 21 '18 at 19:31











  • Sure, I'm having difficulties to insert an array (the lppPhysical) inside the cassettes (array of objects) like the above structure. My code only inserts the IppPhysical as an object in the cassettes.

    – Allan Paz
    Nov 22 '18 at 12:24











  • This is still unclear... Am I then correct in assuming that the structure you posted is your current output and that it is not what you want? If so could you please post the desired output?

    – Silmathoron
    Nov 22 '18 at 13:40











  • The mentioned structure is the correct one(mock), I need to translate this structure using boost library, but I am having difficulties on the lppPhysical part(Insert an array of objects as a child of the cassettes, which is an array of objects.

    – Allan Paz
    Nov 22 '18 at 13:50














0












0








0








I see that have a lot of questions very similar to mine, but I don´t see any solutions that fit with my problem.



I' am trying to create a JSON with boost library with the below structure:



{
"event_date": "2018-06-11T09:35:48.867Z",
"event_log": "2018-06-11 09:35:43,253 - recycler [TRACE]: Running recycler::WITHDRAW",
"cassettes": [
{
"value" : "0",
"currency": "BRL",
"CDMType" : "WFS_CDM_TYPEREJECTCASSETTE",
"lppPhysical" : [
{
"positionName" : "BIN1A",
"count" : "3"
}
]
},
{.....},{.....}
]
}


Below we will have the code that I have now:



boost::property_tree::ptree children, children2, child, child1, child2, child3, child4, child5, cassettes;

child1.put("value", "cash_unit->ulValues");
child2.put("currency", "std::string(cash_unit->cCurrencyID).substr(0, 3)");
child3.put("CDMType", "cash_unit->usType");

child4.put("lppPhysical.positionName", "ph_unit->lpPhysicalPositionName");
child5.put("lppPhysical.count", "cash_unit->ulCount");

cassettes.put("event_date", "2018-06-11T09:35:48.867Z");
cassettes.put("event_log", "2018-06-11 09:35:43,253 - recycler [TRACE]: Running recycler::WITHDRAW");

children.push_back(std::make_pair("", child1));
children.push_back(std::make_pair("", child2));
children.push_back(std::make_pair("", child3));

children2.push_back(std::make_pair("", child4));
children2.push_back(std::make_pair("", child5));

cassettes.add_child("cassettes", children);

write_json("C:\Temp\test.json", cassettes);`


Summarizing, I'm having difficulties to put an array of objects inside of an array of objects.










share|improve this question
















I see that have a lot of questions very similar to mine, but I don´t see any solutions that fit with my problem.



I' am trying to create a JSON with boost library with the below structure:



{
"event_date": "2018-06-11T09:35:48.867Z",
"event_log": "2018-06-11 09:35:43,253 - recycler [TRACE]: Running recycler::WITHDRAW",
"cassettes": [
{
"value" : "0",
"currency": "BRL",
"CDMType" : "WFS_CDM_TYPEREJECTCASSETTE",
"lppPhysical" : [
{
"positionName" : "BIN1A",
"count" : "3"
}
]
},
{.....},{.....}
]
}


Below we will have the code that I have now:



boost::property_tree::ptree children, children2, child, child1, child2, child3, child4, child5, cassettes;

child1.put("value", "cash_unit->ulValues");
child2.put("currency", "std::string(cash_unit->cCurrencyID).substr(0, 3)");
child3.put("CDMType", "cash_unit->usType");

child4.put("lppPhysical.positionName", "ph_unit->lpPhysicalPositionName");
child5.put("lppPhysical.count", "cash_unit->ulCount");

cassettes.put("event_date", "2018-06-11T09:35:48.867Z");
cassettes.put("event_log", "2018-06-11 09:35:43,253 - recycler [TRACE]: Running recycler::WITHDRAW");

children.push_back(std::make_pair("", child1));
children.push_back(std::make_pair("", child2));
children.push_back(std::make_pair("", child3));

children2.push_back(std::make_pair("", child4));
children2.push_back(std::make_pair("", child5));

cassettes.add_child("cassettes", children);

write_json("C:\Temp\test.json", cassettes);`


Summarizing, I'm having difficulties to put an array of objects inside of an array of objects.







c++ arrays object boost






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 20:00









Silmathoron

1,0861921




1,0861921










asked Nov 21 '18 at 19:20









Allan PazAllan Paz

1




1













  • Hi Allan Paz, from your question, it is not clear what the problem is; could you specify what goes wrong? (error message, wrong output...) so it is easier for other people to answer your question?

    – Silmathoron
    Nov 21 '18 at 19:31











  • Sure, I'm having difficulties to insert an array (the lppPhysical) inside the cassettes (array of objects) like the above structure. My code only inserts the IppPhysical as an object in the cassettes.

    – Allan Paz
    Nov 22 '18 at 12:24











  • This is still unclear... Am I then correct in assuming that the structure you posted is your current output and that it is not what you want? If so could you please post the desired output?

    – Silmathoron
    Nov 22 '18 at 13:40











  • The mentioned structure is the correct one(mock), I need to translate this structure using boost library, but I am having difficulties on the lppPhysical part(Insert an array of objects as a child of the cassettes, which is an array of objects.

    – Allan Paz
    Nov 22 '18 at 13:50



















  • Hi Allan Paz, from your question, it is not clear what the problem is; could you specify what goes wrong? (error message, wrong output...) so it is easier for other people to answer your question?

    – Silmathoron
    Nov 21 '18 at 19:31











  • Sure, I'm having difficulties to insert an array (the lppPhysical) inside the cassettes (array of objects) like the above structure. My code only inserts the IppPhysical as an object in the cassettes.

    – Allan Paz
    Nov 22 '18 at 12:24











  • This is still unclear... Am I then correct in assuming that the structure you posted is your current output and that it is not what you want? If so could you please post the desired output?

    – Silmathoron
    Nov 22 '18 at 13:40











  • The mentioned structure is the correct one(mock), I need to translate this structure using boost library, but I am having difficulties on the lppPhysical part(Insert an array of objects as a child of the cassettes, which is an array of objects.

    – Allan Paz
    Nov 22 '18 at 13:50

















Hi Allan Paz, from your question, it is not clear what the problem is; could you specify what goes wrong? (error message, wrong output...) so it is easier for other people to answer your question?

– Silmathoron
Nov 21 '18 at 19:31





Hi Allan Paz, from your question, it is not clear what the problem is; could you specify what goes wrong? (error message, wrong output...) so it is easier for other people to answer your question?

– Silmathoron
Nov 21 '18 at 19:31













Sure, I'm having difficulties to insert an array (the lppPhysical) inside the cassettes (array of objects) like the above structure. My code only inserts the IppPhysical as an object in the cassettes.

– Allan Paz
Nov 22 '18 at 12:24





Sure, I'm having difficulties to insert an array (the lppPhysical) inside the cassettes (array of objects) like the above structure. My code only inserts the IppPhysical as an object in the cassettes.

– Allan Paz
Nov 22 '18 at 12:24













This is still unclear... Am I then correct in assuming that the structure you posted is your current output and that it is not what you want? If so could you please post the desired output?

– Silmathoron
Nov 22 '18 at 13:40





This is still unclear... Am I then correct in assuming that the structure you posted is your current output and that it is not what you want? If so could you please post the desired output?

– Silmathoron
Nov 22 '18 at 13:40













The mentioned structure is the correct one(mock), I need to translate this structure using boost library, but I am having difficulties on the lppPhysical part(Insert an array of objects as a child of the cassettes, which is an array of objects.

– Allan Paz
Nov 22 '18 at 13:50





The mentioned structure is the correct one(mock), I need to translate this structure using boost library, but I am having difficulties on the lppPhysical part(Insert an array of objects as a child of the cassettes, which is an array of objects.

– Allan Paz
Nov 22 '18 at 13:50












1 Answer
1






active

oldest

votes


















0














Finally found a solution to my case, it's pretty simple but was hard to find since I am not too familiar with this library.



        //LppPhysical insertion
lppPhysicalInfo.put("positionName", ph_unit->lpPhysicalPositionName);
lppPhysicalInfo.put("count", cash_unit->ulCount);
lppPhysical.push_back(std::make_pair("", lppPhysicalInfo));

//Cassettes insertions
cassettesInfo.put("value", cash_unit->ulValues);
cassettesInfo.put("currency", std::string(cash_unit->cCurrencyID).substr(0, 3));
cassettesInfo.put("CDMType", cash_unit->usType);
cassettesInfo.add_child("lppPhysical", lppPhysical.get_child(""));
cassettes.push_back(std::make_pair("", cassettesInfo));

//External information insertion
arquivo.put("event_date", "DateValue");
arquivo.put("event_log", "LogValue");
arquivo.add_child("cassettes", cassettes);

//Json creator
write_json("C:\Temp\assassino.json", arquivo);


On the lppPhysical I just make a pair with all its content and on the Cassettes' insertion I just added the lppPhysical as a child of the cassettes and that's it. Now the lppPhysical is an array of object insde the Cassettes which is also an array of objects






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419171%2fiam-having-some-problems-with-boost-json-in-c%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Finally found a solution to my case, it's pretty simple but was hard to find since I am not too familiar with this library.



            //LppPhysical insertion
    lppPhysicalInfo.put("positionName", ph_unit->lpPhysicalPositionName);
    lppPhysicalInfo.put("count", cash_unit->ulCount);
    lppPhysical.push_back(std::make_pair("", lppPhysicalInfo));

    //Cassettes insertions
    cassettesInfo.put("value", cash_unit->ulValues);
    cassettesInfo.put("currency", std::string(cash_unit->cCurrencyID).substr(0, 3));
    cassettesInfo.put("CDMType", cash_unit->usType);
    cassettesInfo.add_child("lppPhysical", lppPhysical.get_child(""));
    cassettes.push_back(std::make_pair("", cassettesInfo));

    //External information insertion
    arquivo.put("event_date", "DateValue");
    arquivo.put("event_log", "LogValue");
    arquivo.add_child("cassettes", cassettes);

    //Json creator
    write_json("C:\Temp\assassino.json", arquivo);


    On the lppPhysical I just make a pair with all its content and on the Cassettes' insertion I just added the lppPhysical as a child of the cassettes and that's it. Now the lppPhysical is an array of object insde the Cassettes which is also an array of objects






    share|improve this answer




























      0














      Finally found a solution to my case, it's pretty simple but was hard to find since I am not too familiar with this library.



              //LppPhysical insertion
      lppPhysicalInfo.put("positionName", ph_unit->lpPhysicalPositionName);
      lppPhysicalInfo.put("count", cash_unit->ulCount);
      lppPhysical.push_back(std::make_pair("", lppPhysicalInfo));

      //Cassettes insertions
      cassettesInfo.put("value", cash_unit->ulValues);
      cassettesInfo.put("currency", std::string(cash_unit->cCurrencyID).substr(0, 3));
      cassettesInfo.put("CDMType", cash_unit->usType);
      cassettesInfo.add_child("lppPhysical", lppPhysical.get_child(""));
      cassettes.push_back(std::make_pair("", cassettesInfo));

      //External information insertion
      arquivo.put("event_date", "DateValue");
      arquivo.put("event_log", "LogValue");
      arquivo.add_child("cassettes", cassettes);

      //Json creator
      write_json("C:\Temp\assassino.json", arquivo);


      On the lppPhysical I just make a pair with all its content and on the Cassettes' insertion I just added the lppPhysical as a child of the cassettes and that's it. Now the lppPhysical is an array of object insde the Cassettes which is also an array of objects






      share|improve this answer


























        0












        0








        0







        Finally found a solution to my case, it's pretty simple but was hard to find since I am not too familiar with this library.



                //LppPhysical insertion
        lppPhysicalInfo.put("positionName", ph_unit->lpPhysicalPositionName);
        lppPhysicalInfo.put("count", cash_unit->ulCount);
        lppPhysical.push_back(std::make_pair("", lppPhysicalInfo));

        //Cassettes insertions
        cassettesInfo.put("value", cash_unit->ulValues);
        cassettesInfo.put("currency", std::string(cash_unit->cCurrencyID).substr(0, 3));
        cassettesInfo.put("CDMType", cash_unit->usType);
        cassettesInfo.add_child("lppPhysical", lppPhysical.get_child(""));
        cassettes.push_back(std::make_pair("", cassettesInfo));

        //External information insertion
        arquivo.put("event_date", "DateValue");
        arquivo.put("event_log", "LogValue");
        arquivo.add_child("cassettes", cassettes);

        //Json creator
        write_json("C:\Temp\assassino.json", arquivo);


        On the lppPhysical I just make a pair with all its content and on the Cassettes' insertion I just added the lppPhysical as a child of the cassettes and that's it. Now the lppPhysical is an array of object insde the Cassettes which is also an array of objects






        share|improve this answer













        Finally found a solution to my case, it's pretty simple but was hard to find since I am not too familiar with this library.



                //LppPhysical insertion
        lppPhysicalInfo.put("positionName", ph_unit->lpPhysicalPositionName);
        lppPhysicalInfo.put("count", cash_unit->ulCount);
        lppPhysical.push_back(std::make_pair("", lppPhysicalInfo));

        //Cassettes insertions
        cassettesInfo.put("value", cash_unit->ulValues);
        cassettesInfo.put("currency", std::string(cash_unit->cCurrencyID).substr(0, 3));
        cassettesInfo.put("CDMType", cash_unit->usType);
        cassettesInfo.add_child("lppPhysical", lppPhysical.get_child(""));
        cassettes.push_back(std::make_pair("", cassettesInfo));

        //External information insertion
        arquivo.put("event_date", "DateValue");
        arquivo.put("event_log", "LogValue");
        arquivo.add_child("cassettes", cassettes);

        //Json creator
        write_json("C:\Temp\assassino.json", arquivo);


        On the lppPhysical I just make a pair with all its content and on the Cassettes' insertion I just added the lppPhysical as a child of the cassettes and that's it. Now the lppPhysical is an array of object insde the Cassettes which is also an array of objects







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 13:58









        Allan PazAllan Paz

        1




        1
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419171%2fiam-having-some-problems-with-boost-json-in-c%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to change which sound is reproduced for terminal bell?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

            Can I use Tabulator js library in my java Spring + Thymeleaf project?