Array Custom Functions: Assemble JSON Elements and JSON Arrays from lists for use with "JSONSetElement"

Document created by automationusallc on May 5, 2017Last modified by automationusallc on May 8, 2017
Version 10Show Document
  • View in full screen mode

Use these two custom functions to compose well formed JSON Elements and/or JSON Arrays from any sort of list (return separated or not).

Tip: These "lists" could easily come from the two new "JSONListKeys" and "JSONListVaues" functions in FileMaker16

 

Once composed, your new JSON data can be readily inserted into the "value" parameter of the new "JSON SetElement" function in FileMaker 16.

 

BrianDunning:

ArrayReformat ( valueList ; quoteStyle ; braceStyle ; newSeparator ; oldSeparator )

ArrayCombine ( array1 ; array2 ; startposition ; separator )

 

Github:

ArrayReformat.fmfn

ArrayCombine.fmfn

 

Example 1:

Let's assume $$yourJSON =

{

  "records" :

  [

       {

            "a" :

            {

                 "label1" : 11

            }

       }

  ]

}

then the formula below will append a new "records" array with index of "b"

Let ( [

list1 = ArrayReformat ( "Label1¶Label2¶Label3¶Label4" ; "\"" ; "null" ; "¶" ; "" ) ;

list2 = ArrayReformat ( "fantastic!¶...but what about¶a syntax for adding¶an element to the END of an array?" ; "\"" ; "null" ; "¶" ; "" ) ;

$newJSON = ArrayReformat ( ArrayCombine ( list1 ; list2 ; 1 ; " : " ) ; " " ; "{}" ; "," ; "" )

] ;

//calculation

JSONFormatElements ( JSONSetElement ( $$yourJSON ; "records[1].b" ; $newJSON ; JSONRaw ) )

)

 

Result 1:

{

  "records" :

  [

       {

            "a" :

            {

                 "label1" : 11

            }

       },

       {

            "b" :

            {

                 "Label1" : "fantastic!",

                 "Label2" : "...but what about",

                 "Label3" : "a syntax for adding",

                 "Label4" : "an element to the END of an array?"

            }

       }

  ]

}

Attachments

    Outcomes