Brian Dunning's FileMaker Custom Functions

Json2Vars ( json )

Create local variables for all keys belongs to the JSON document's root node.

  Be the first to rate this function Log in to vote

Pascal Surget   Pascal Surget - Show more from this author
Creaxion solutions
https://www.creaxion.ca

Share on Facebook Share on Twitter

  Sample input:
{ "id":123, "color":"blue" }
  Sample output:
$id (123), $color ("blue")

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

* @SIGNATURE:
* Json2Var ( json )
* Based on the custom function of Fabrice Nordmann xml2var.
* Thanks Fabrice, I used your custom function for so many years.
*
* @PARAMETERS:
* json - JSON data
*
* @HISTORY:
* CREATED on 2021-05-20 by Pascal Surget
*
* @PURPOSE:
* Create local variables for all keys belongs to the JSON document's root node.
* For example, given the following JSON, this custom function will create $id and $color variables: { "id" : "123", "color" : "blue" }
*
* @RESULT:
* This custom function will return an error code as a result.
* 0 means success or empty JSON.
* 5 means invalid JSON.
* 1204 means one of the JSON root keys did not conform to the FileMaker naming restrictions for variable and fields.
* Pre-19 clients will return "?".
*
* @ERRORS:
* Errors will be indicated in the custom function result using standard FileMaker error codes: https://help.claris.com/en/pro-help/content/error-codes.html
*
* @NOTES:
* Keys must be named following the same naming restrictions as FileMaker variables and fields: https://help.claris.com/en/pro-help/content/specify-calculation.html
*
* @DEPENDENCIES:
* Does not require any other custom functions. Requires v19 or later client. Pre-19 clients will return "?".

 

Comments

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: