5 Replies Latest reply on Jun 26, 2017 6:01 AM by beverly

    Problem Parsing JSON from Dropbox

    fineas

      Hi All,

       

      I am a novice when it comes to working with JSON.  I didn't even know what it was two weeks ago.  However, I have been learning what I can and am experimenting with the Dropbox API.

       

      Through much trial and error, I have been able to connect and use the list_folder function to get back a JSON response.  I am able to parse most of it using Filemaker 16's new functions.    However one of the keys begins with a dot ".".   Specifically, it is ".tag" which returns as values either "file" or "folder".   The dot is throwing me off.  None of their other keys has this dot.    How would I write the JSONGetElement step to retrieve a value where the key is ".tag"?   Why would they use the "dot" in the first place?

       

      To get the other values, I am using, for example-   JSONGetElement ( $$JSON ; "entries[1].name" ).   

       

      JSONGetElement ( $$JSON ; "entries[1]..tag" )  does not work.

       

      I would greatly appreciate anyone's help with this.

        • 1. Re: Problem Parsing JSON from Dropbox
          TomHays

          fineas wrote:

           

          working with JSON.... with the Dropbox API.

           

          ...However one of the keys begins with a dot ".". Specifically, it is ".tag" which returns as values either "file" or "folder". The dot is throwing me off.... Why would they use the "dot" in the first place?

           

          You are not alone.

           

          People have been having problems with their choice to use ".key" as a key long before FileMaker added JSON functions.  Many if not most of the JSON handling functions in other languages also have trouble with this.

           

          Why did they choose to use a dot as the first character of the key name?  I suspect some programmer at Dropbox thought it would be funny.

           

          A workaround may be to Substitute(yourJSONString; "\".key\""; "\"dotkey\"") and then work with for "dotkey" as the key name instead of ".key".

           

           

          -Tom

          4 of 4 people found this helpful
          • 2. Re: Problem Parsing JSON from Dropbox
            fineas

            Thank you, Tom.   That did the trick.  Saved me hours of pulling my hair out (and I don't have much left to pull out).

             

            -David

            • 3. Re: Problem Parsing JSON from Dropbox
              wimdecorte

              TomHays wrote:

              Many if not most of the JSON handling functions in other languages also have trouble with this.

               

              To expand a bit on this for other people that will find this thread and are new to JSON: the "." in JSON parsing is to construct a path to the key you are after.  So keys themselves really should not have "." in their names.

               

              Given a JSON object like this, representing a purchase order and its items:

              {

                "Number": "2175135525",

                "SubmitDate": "2016-10-31T05:00:00+00:00",

                "Amount": 1601,

                "SubTotal": 1601,

                "TaxTotal": 120.08,

                "FreightTotal": 0,

                "GrandTotal": 1721.08,

                "POItems": [

                  {

                    "ItemRefNumber": "1",

                    "PartNumber": 1402,

                    "PartType": "UNSPSC",

                    "PartDsc": "ZBRW1402(W1402 STUD, WHEEL, M22 X 1.5)",

                    "Quantity": "100",

                    "UnitPrice": 7.73,

                    "itemTotal": 773

                  },

                  {

                    "ItemRefNumber": "2",

                    "PartNumber": 1403,

                    "PartType": "UNSPSC",

                    "PartDsc": "ZBRW1403(W1403 STUD, WHEEL, M22 X 1.5)",

                    "Quantity": "100",

                    "UnitPrice": 8.28,

                    "itemTotal": 828

                  }

                ]

              }

               

              To get the part number of the 2nd PO item the JSON path would look like this:

              JSONGetElement ( $json ; "POItems[1].PartNumber" )

               

              Where the "." is part of the path syntax to indicate that 'PartNumber' is a sub key of the 'POitems' key

              2 of 2 people found this helpful
              • 4. Re: Problem Parsing JSON from Dropbox
                bigtom

                M22x1.5? That sounds kinda like big tractor parts.

                • 5. Re: Problem Parsing JSON from Dropbox
                  beverly

                  The "dot notation" is used in more than just JSON/JavaScript. Early on it was/is a way to read XML! The folks at dropbox need to get with the program. LOL

                  There are several articles on the notation. This is a start:

                  * Property accessors - JavaScript | MDN

                  the [] is the index selector (starting with 0)

                  or the [] is the 'named' selector

                  the . is another way to get the values:

                  parent.child.child.child

                  A couple of good JSON tutorials:

                  http://json.org/ (bilingual examples!)

                  https://www.w3schools.com/js/js_json_intro.asp

                   

                  Beverly