I have the following JSON file:
{
"outer_size":2,
"inner_size":{
"length_one":2,
"length_two":1
}
}
I will use this info to create a new JSON file, whose dimensions are determined by outer_size
, inner_size
, length_one
and length_two
. The structure I want to generate has the following form
[
{
"a":[
{
"a_one":1
},
{
"a_two":2
}
]
},
{
"b":[
{
"b_one":1
}
]
}
]
This structure contains two "outer" variables a
and b
because outer_size=2
.
a
contains two "inner" variables a_one
and a_two
, while b
contains one "inner" variable b_one
. This is because inner_size
is 2 and 1, respectively.
Question Based on a given outer_size
, inner_size
, length_one
and length_two
, what is the best way to generate a JSON structure with those dimensions? Can/should it be done with classes?
Please note the following
- The value of
outer_size
must always be equal to the number oflength_XX
-specifications (in the above example 2). In case it is 3, we will have to specifylength_three
too. - The specific values of
a_one
,a_ two
etc... can be whatever for this example. Now my main concern is merely to construct the basic structure. - I'm using Nlohmann's JSON library for reading the initial JSON file.