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
https://www.vbzs.nl

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": "www.apple.com","EmailAddresses": [{"Address": "s.zhuravetc@apple.com","Type": "Work"},{"Address": "sofiaz98@yahoo.com","Type": "Personal"}]}
  Sample output:
In the dataviewer the first input would result in values in the following variables:

$Company : Apple Computer Inc.
$First.Name : Sofia
$Last.Name : Zhuravetc
$Website : www.apple.com
$EmailAddresses : [{"Address": "s.zhuravetc@apple.com","Type": "Work"},{"Address": "sofiaz98@yahoo.com","Type": "Personal"}]


A $[namespace]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: https://www.filemakertips.nl

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.

 

Comments

Menno van Beek   Menno van Beek, Van Beek Zakelijke Software
Jan 21, 2022
Corrected 2 little error: The name in the recursive call: JSON2ScriptParameters and added a filter for illegal variablenames
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. 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 20 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: