Parsing C++ vector to JSON file

Joined
6/4/22
Messages
40
Points
118
Hi Forum,

I am trying to parse some C++ vector values into a JSON file in a following structure.
I am using the boost libraries such as <boost/property_tree/json_parser.hpp>.

However, I don't know how to save the vector data into the JSON in a format like: "Spot": [1.0, 2.0, 3.0, 4.0, 5.0].

Below is the data structure I want to achieve.
JSON:
{
    "Crank-Nicolson" : {
        "Spot": [1.0, 2.0, 3.0, 4.0, 5.0],
        "PV": [11.0, 12.0, 13.0, 14.0, 15.0],
        "Delta": [21.0, 22.0, 23.0, 24.0, 25.0],
    },
    "Explicit Euler" : {
        "Spot": [1.0, 2.0, 3.0, 4.0, 5.0],
        "PV": [11.0, 12.0, 13.0, 14.0, 15.0],
        "Delta": [21.0, 22.0, 23.0, 24.0, 25.0],
    },
    "Implicit Euler" : {
        "Spot": [1.0, 2.0, 3.0, 4.0, 5.0],
        "PV": [11.0, 12.0, 13.0, 14.0, 15.0],
        "Delta": [21.0, 22.0, 23.0, 24.0, 25.0],
    }
}
 
Tickled this a bit and got the attached main.cpp working just fine. I'd probably stick to an already created and optimized library like the one mentioned above. Beats sad looping :)
Thanks for the reply.
I did that too, but was think if there is a way to parse the vector data directly into a "[1,2,3,4]" format instead, which would reduce the file size without duplicated strings.
 
Back
Top Bottom