Set Variable chaining for JSON construction
BeginnerBuild complex JSON payloads incrementally using chained Set Variable steps and FileMaker's JSON functions.
What you'll learn
- How to initialize an empty JSON object in a variable
- How to add keys with JSONSetElement one step at a time
- How to build a JSON array with JSONSetElement and numeric indexes
- How to nest JSON objects within a parent object
- How to format multi-line JSONSetElement calls for readability
FileMaker's JSON functions (JSONSetElement, JSONGetElement, JSONDeleteElement, JSONListKeys) let you build structured data entirely within variables. Rather than concatenating strings manually, you use JSONSetElement to add keys to an accumulating JSON object, producing valid JSON that is ready for Insert from URL, Perform Script parameters, or Exit Script results.
Build a flat JSON object incrementally
Start with an empty object "{}". Each JSONSetElement call takes the current variable, adds a key, and returns the updated JSON. Assign the result back to the same variable. The third argument specifies the value type: JSONString, JSONNumber, JSONBoolean, JSONArray, or JSONObject.
Set Variable [ $payload ; Value: "{}" ]
Set Variable [ $payload ; Value: JSONSetElement ( $payload ; "name" ; Contacts::FullName ; JSONString ) ]
Set Variable [ $payload ; Value: JSONSetElement ( $payload ; "email" ; Contacts::Email ; JSONString ) ]
Set Variable [ $payload ; Value: JSONSetElement ( $payload ; "accountID" ; Contacts::AccountID ; JSONNumber ) ]
Set Variable [ $payload ; Value: JSONSetElement ( $payload ; "active" ; 1 ; JSONBoolean ) ]
# $payload is now:
# {"name":"Jane Smith","email":"jane@example.com","accountID":1042,"active":true}Sign in to track your progress and pick up where you left off.
Sign in to FM Dojo