Problem loading json file from BinaryData in project resources (Visual Studio 2019)

Hi, I am having trouble reading the data from a .json file that I embedded in my projucer project resources as binary data. This is what I currently have:

(jsonFile is a juce::File, and the json file is named “data.json”)
//------------------------------------------------
jsonFile(BinaryData::data_json);
auto fileText = jsonFile.loadFileAsString();
data = JSON::parse(fileText);

numChannels = data[“num_channels”];
outputChannels = data[“output_channels”];
//------------------------------------------------

…and so on to read the json fields. However, the fields aren’t being read correctly, and all come out as “0”. The .json file is about 400kb in size. Using the debugger, it looks like it’s not able to loadFileAsString(), but if I drill down into the “jsonFile” variable I can see the expected data from the file under the “Value” field in the debugger, but with backslashes added prior to the parentheses surrounding each value. When reading the same json file not included in BinaryData, and just loaded separately from the projucer project it works fine. I’m guessing I need some kind of conversion to use the binary form of the json file? The reason I want to do it this way is so I can embed the json file in the .vst.

Thank you,

-Keith

Data that you put into the BinaryData is in memory, not out in the file system. juce::File operates on a file, not memory. I can’t even imagine how the first three lines of that code even work…

I think it should be something like, although I am not sure of the exact call…

data = JSON::parse(BinaryData::data_json);
1 Like

That fixed it, thanks for the quick response! I was trying to make it too complicated.