<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic AppFramework File Folder Bug? - readJsonFile  and writeJsonFile  methods do not allow top-level array in JSON data in ArcGIS AppStudio Questions</title>
    <link>https://community.esri.com/t5/arcgis-appstudio-questions/appframework-file-folder-bug-readjsonfile-and/m-p/1211805#M4357</link>
    <description>&lt;P&gt;As far as I know it is perfectly valid for JSON data to contain a top-level array, for example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;'["cat","dog"]'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The JSON standards seem to allow this and if you pass that to JSON.parse you get an array.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Here is a short POC to reproduce the issue:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;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)
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 12 Sep 2022 21:10:26 GMT</pubDate>
    <dc:creator>JamesGough</dc:creator>
    <dc:date>2022-09-12T21:10:26Z</dc:date>
    <item>
      <title>AppFramework File Folder Bug? - readJsonFile  and writeJsonFile  methods do not allow top-level array in JSON data</title>
      <link>https://community.esri.com/t5/arcgis-appstudio-questions/appframework-file-folder-bug-readjsonfile-and/m-p/1211805#M4357</link>
      <description>&lt;P&gt;As far as I know it is perfectly valid for JSON data to contain a top-level array, for example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;'["cat","dog"]'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The JSON standards seem to allow this and if you pass that to JSON.parse you get an array.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Here is a short POC to reproduce the issue:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;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)
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 21:10:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-appstudio-questions/appframework-file-folder-bug-readjsonfile-and/m-p/1211805#M4357</guid>
      <dc:creator>JamesGough</dc:creator>
      <dc:date>2022-09-12T21:10:26Z</dc:date>
    </item>
    <item>
      <title>Re: AppFramework File Folder Bug? - readJsonFile  and writeJsonFile  methods do not allow top-level array in JSON data</title>
      <link>https://community.esri.com/t5/arcgis-appstudio-questions/appframework-file-folder-bug-readjsonfile-and/m-p/1212032#M4358</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/119731"&gt;@JamesGough&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;You are correct that arrays can be used in JSON at the top level. This would be considered a JSONArray. However, the FileFolder functions writeJsonFile or readJson handle JSONObjects which expect {} at top level. You can use your code snippet above and change line 33 to this and it will work.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var okWrite = folder.writeJsonFile("data1.json", {data1});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2022-09-13 at 9.16.44 AM.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51035i102EDD1FBA7CB414/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2022-09-13 at 9.16.44 AM.png" alt="Screen Shot 2022-09-13 at 9.16.44 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Trevor&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 16:18:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-appstudio-questions/appframework-file-folder-bug-readjsonfile-and/m-p/1212032#M4358</guid>
      <dc:creator>TrevorFrame</dc:creator>
      <dc:date>2022-09-13T16:18:07Z</dc:date>
    </item>
    <item>
      <title>Re: AppFramework File Folder Bug? - readJsonFile  and writeJsonFile  methods do not allow top-level array in JSON data</title>
      <link>https://community.esri.com/t5/arcgis-appstudio-questions/appframework-file-folder-bug-readjsonfile-and/m-p/1212039#M4359</link>
      <description>&lt;P&gt;Thanks for the response, I guess I never considered a JSONArray to be a distinct format from a JSONObject. In javascript or python the JSON encoder functions will take either arrays or objects when writing JSON. Maybe that is different in more strictly typed languages though.&lt;/P&gt;&lt;P&gt;It's easy to wrap an array within an object when passing to writeJsonFile but it seems somewhat redundant to have to add that extra key when all your really care about is the array. Another option is to just use writeTextFile and readTextFile along with JSON.stringify and JSON.parse&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 16:38:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-appstudio-questions/appframework-file-folder-bug-readjsonfile-and/m-p/1212039#M4359</guid>
      <dc:creator>JamesGough</dc:creator>
      <dc:date>2022-09-13T16:38:27Z</dc:date>
    </item>
  </channel>
</rss>

