Brian Dunning's FileMaker Custom Functions

JSONtoJSONSetElement

Convert JSON into a JSONSetElement calculation

  Be the first to rate this function Log in to vote

Jason Wood   Jason Wood - Show more from this author
Define Database
https://www.definedatabase.com

Share on Facebook Share on Twitter

  Sample input:
JSONtoJSONSetElement ( $json )

/* $json =

{
"string": "Hello, world!",
"number": 42,
"boolean": true,
"nullValue": null,
"array": [1, "two", false, null, {"nestedObject": "insideArray"}],
"object": {
"level1Key": "Level 1 value",
"nestedObject": {
"level2Key": 3.14,
"anotherNestedObject": {
"level3Key": {
"deepBoolean": false,
"deepArray": [true, null, {"deepestKey": "Deep inside"}]
}
}
}
}
}

*/
  Sample output:
JSONSetElement ( "" ;
[ "array[0]" ; 1 ; JSONNumber ];
[ "array[1]" ; "two" ; JSONString ];
[ "array[2]" ; 0 ; JSONBoolean ];
[ "array[3]" ; "" ; JSONNull ];
[ "array[4].nestedObject" ; "insideArray" ; JSONString ];
[ "boolean" ; 1 ; JSONBoolean ];
[ "nullValue" ; "" ; JSONNull ];
[ "number" ; 42 ; JSONNumber ];
[ "object.level1Key" ; "Level 1 value" ; JSONString ];
[ "object.nestedObject.anotherNestedObject.level3Key.deepArray[0]" ; 1 ; JSONBoolean ];
[ "object.nestedObject.anotherNestedObject.level3Key.deepArray[1]" ; "" ; JSONNull ];
[ "object.nestedObject.anotherNestedObject.level3Key.deepArray[2].deepestKey" ; "Deep inside" ; JSONString ];
[ "object.nestedObject.anotherNestedObject.level3Key.deepBoolean" ; 0 ; JSONBoolean ];
[ "object.nestedObject.level2Key" ; 3.14 ; JSONNumber ];
[ "string" ; "Hello, world!" ; JSONString ]
)

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

The intended use is as a developer tool, for situations where you have sample JSON and need to create a JSONSetElement calculation to create a similar JSON object.

 

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 21 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: