I want to convert a text file to JSON, but in a very particular way. My text file looks like this:
Data 1:
datapoint1-1 = 21
datapoint1-2 = 23
Data 2:
datapoint2-1 = 21
datapoint2-2 = 23
datapoint2-3 = 23
I want to create a JSON file that separates this data like this:
{
{
"Data": "1",
"Datapoints": [
{
"datapoint1-1": "21",
"datapoint1-2": "23"
}
]
},
{
"Data": "2",
"Datapoints": [
{
"datapoint2-1": "21",
"datapoint2-2": "23",
"datapoint2-3": "23"
}
]
}
}
My first step has split the data into 2 arrays inside an array. The first array is Data 1 plus its data-points and the second is Data 2 plus its data-points.
Now I am stuck on how I can convert those arrays into the JSON format I want. Does anyone have an idea? or can direct me in the right direction for this?
Thanks,
JSON.stringifytend to convert text format (those are like json format) to proper json format.Datapointsan array if it's always just going to have one item?