Hello, I am trying to create a copy of a JSON file that looks like that :
[
{
"id": "header",
"inverLeft": true,
"inverRight": false
},
{
"id": 0,
"linked": true,
"comments": "First stereo filter",
"left": {
"central_frequency": 1000.0,
"quality_factor": 2.0,
"amplitude": 5.0,
"filter_type": "low_pass",
"bypass": false
},
"right": {
"central_frequency": 1200,
"quality_factor": 0.9,
"amplitude": 5,
"filter_type": "low_pass",
"bypass": false
}
},
{
"id": 0,
"linked": true,
"comments": "second stereo filter",
"left": {
"central_frequency": 1000.0,
"quality_factor": 2.0,
"amplitude": 5.0,
"filter_type": "low_pass",
"bypass": false
},
"right": {
"central_frequency": 1200,
"quality_factor": 0.9,
"amplitude": 5,
"filter_type": "low_pass",
"bypass": false
}
}
]
Basically it is a list of object, the first is a header, the others are stereo filters that contains individual right and left filters.
I want to be able to create a copy of it and export it too. For that I have a load function like so :
void BiquadChainAudioProcessor::loadFile(const juce::String& path)
{
filePath = path;
juce::File file(path);
juce::String extension = file.getFileExtension();
if (extension == ".json") {
juce::String content = file.loadFileAsString();
juce::var parsedJSON = juce::JSON::parse(content);
copyJSON = parsedJSON;
updateCoefficients();
exportJSON("C:/Users/MyName/Documents/ExportedJSON_direct.json");
}
}
with copyJSON being initialized as : juce::Array<juce::var> copyJSON;
I want to export it to verify if the loadFile function do it well :
void BiquadChainAudioProcessor::exportJSON(const juce::String& exportPath)
{
juce::var jsonObject(copyJSON);
juce::String jsonString = juce::JSON::toString(jsonObject);
juce::File jsonFile(exportPath);
jsonFile.replaceWithText(jsonString);
}
The thing is that the exported JSON looks like that :
[
[
{
"id": "header",
"inverLeft": true,
"inverRight": false
},
{
"id": 0,
"linked": true,
"comments": "First stereo filter",
"left": {
"central_frequency": 1000.0,
"quality_factor": 2.0,
"amplitude": 5.0,
"filter_type": "low_pass",
"bypass": false
},
"right": {
"central_frequency": 1200,
"quality_factor": 0.9,
"amplitude": 5,
"filter_type": "low_pass",
"bypass": false
}
},
{
"id": 0,
"linked": true,
"comments": "second stereo filter",
"left": {
"central_frequency": 1000.0,
"quality_factor": 2.0,
"amplitude": 5.0,
"filter_type": "low_pass",
"bypass": false
},
"right": {
"central_frequency": 1200,
"quality_factor": 0.9,
"amplitude": 5,
"filter_type": "low_pass",
"bypass": false
}
}
]
]
which is the data I want but in a nested list. There too ‘[[.]]’ instead of ‘[.]’. So naturally I tryied to take the element 0 of it when loading by modifying the function like so :
void BiquadChainAudioProcessor::loadFile(const juce::String& path)
{
filePath = path;
juce::File file(path);
juce::String extension = file.getFileExtension();
if (extension == ".json") {
juce::String content = file.loadFileAsString();
juce::var parsedJSON = juce::JSON::parse(content);
copyJSON = parsedJSON[0];
updateCoefficients();
exportJSON("C:/Users/MyName/Documents/ExportedJSON_direct.json");
}
}
But I end up with that :
[
{
"id": "header",
"inverLeft": true,
"inverRight": false
}
]
which indeed is a list but it contains only the first element of the desired list.
So to summarize, either I have a list containing the list that I want or I have the first element of the list that I want. That is bugging me because I want the middle of that.
Thank you for any help, don’t hesitate to ask if I forgot something.