AnsweredAssumed Answered

How to script creation of a JSON array from records, without eSQL, XML

Question asked by triac on May 18, 2018
Latest reply on May 18, 2018 by Brian Hamm

I am brand new to JSON and was looking for a simple, FileMaker-native way to create a JSON array of field names and their data, from a found set of records. I read the six page thread about how to do it with eSQL, but that's not what I am looking for, that was much too complicated for me needs. Here's what I've got so far, which doesn't work:

 

Go to Record/Request/Page [ First ]

Loop

 

Set Variable [ $json ; Value:

     JSONSetElement ( $json;

             [ "id" ; Product::id ; JSONString ] ;

             [ "color" ; Product::Color ; JSONString ] ;

             [ "length" ; Product::Length ; JSONNumber ] ;

             [ "width" ; Product::Width ; JSONNumber ]

          ) ]

 

Go to  Record/Request/Page [ Next ; Exit after last: On ]

End Loop

Show Custom Dialog [ $json ]

 

So what am I missing here? By putting $json as the first argument for JSONGetElement, I thought it should build upon itself each time the loop comes around, but it doesn't, it just overwrites the previous value. My output is simply JSON of the last record only, not all of the records in the found set.

 

Specifics:

Not interested in eSQL (it's too complicated for me, and eSQL is too "fragile" for my database building practices ).

Not interested in a recursive Custom Function.

Not interested in using a plugin.

 

Any input is appreciated.

Outcomes