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 - Show more from this author
Van Beek Zakelijke Software https://www.vbzs.nl |
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"}]}
$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, 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 | ||
Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.