As far as I know it is perfectly valid for JSON data to contain a top-level array, for example:
'["cat","dog"]'
The JSON standards seem to allow this and if you pass that to JSON.parse you get an array.
However, the readJsonFile and writeJsonFile methods of File Folder do not seem to allow this. If you use writeJsonFile to serialize an array to a JSON file, you get a file with just "{}" and no data. When using readJsonFIle to read from a JSON file with a top level array, you do not get the data.
Here is a short POC to reproduce the issue:
import QtQuick 2.13
import QtQuick.Controls 2.13
import ArcGIS.AppFramework 1.0
App {
id: app
width: 400
height: 640
FileFolder {
id: folder
path: "./data"
}
Text {
anchors.fill: parent
text: "{My App}"
font.pointSize: 24
color: "black"
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
Component.onCompleted: {
var data1 = ['cat', 'dog'];
var data2 = {animals: ['cat', 'dog']}
var okMake = folder.makeFolder();
var okWrite = folder.writeJsonFile("data1.json", data1); // This data will not be written to the JSON file
var okWrite2 = folder.writeJsonFile("data2.json", data2)
}
}