Brian Dunning's FileMaker Custom Functions

JSON2ScriptParameters ( json ; i ; namespace )

Create scriptvariables from key/value pairs from the root of a JSON and repeating variables from rootarrays

  Average rating: 5.0 (1 vote) Log in to vote

Menno van Beek   Menno van Beek - Show more from this author
Van Beek Zakelijke Software

Share on Facebook Share on Twitter

  Sample input:
first input: JSON2ScriptParameters ( $json ; "" ; "" )

The $json can be a field (or a variable) that contains something like:

{"Company": "Apple Computer Inc.","First.Name": "Sofia","Last.Name": "Zhuravetc","Website": "","EmailAddresses": [{"Address": "","Type": "Work"},{"Address": "","Type": "Personal"}]}

after the first use one of the variables that exist will be $EmailAddresses, which contains an array:
[{"Address": "","Type": "Work"},{"Address": "","Type": "Personal"}]

second input: JSON2ScriptParameters ( $EmailAddresses ; "" ; "Email_" )

  Sample output:
In the dataviewer the first input would result in values in the following variables :
$Company, $First.Name, $Last.Name, $Website and $EmailAddresses

The second input will add a few variables and because it now has a namespace, that namespace will be added to the variablenames:
$Email_Address, $Email_Type, $Email_Address[2], $Email_Type[2] and $Email_max_repetition

The $max_repetition variable contains the highest repetitionnumber of the array and is only created when an array is evaluated.

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

You can download a simple example from this website:

Requirement: FMP18+

This function simply creates variables from a given JSON from the root of a JSON. If the root is an array it will create repeating variables and add variable called $max_repetition or $[namespace]max_repetition if the namespace is given.

This function is only recursive in case an array is evaluated.

Dotted keynames will be properly evaluated (in FMP18 too). For example the key "Last.Name" will evaluate as $Last.Name

This function is not intended for very large chuncks of data, but 100 or 1000 key/value-pairs in the root should not be a problem.



Log in to post comments.


Note: these functions are not guaranteed or supported by Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 16 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: