Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
JSON.SetPathItem
Sets a value in a JSON hierarchy.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
JSON | 6.1 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameters
Parameter | Description | Example |
---|---|---|
json | A JSON text or reference. | "[1,2,3]" |
Path | The path through the json hierarchy as list. For object, pass name of item to choose. For array pass index. For last array you can use special value "append" to add an entry. |
"people¶0¶last" |
Value | The new value as JSON. | "\"Hello\"" |
Result
Returns JSON or error.
Description
Sets a value in a JSON hierarchy.The path describes the way through the hierarchy to find the JSON node to return.
Please pass in new value as JSON.
Version 9.2 automatically creates missing object/array entries. The value parameter will be treated as text if it is not a valid JSON instead of reporting an error.
Implemented FileMaker syntax in v12.4 for JSON element get/set like in JSONSetElement function, so you can use dot notation, [array index] or quoted text in brackets.
Examples
Adds an entry with country:
MBS( "JSON.SetPathItem"; "{\"people\":[{\"first\":\"Christian\",\"last\":\"Schmitz\",\"city\":\"Nickenich\"}]}"; "people¶0¶country"; "\"Germany\"")
Example result:
{
"people": [{
"first": "Christian",
"last": "Schmitz",
"city": "Nickenich",
"country": "Germany"
}]
}
Sets an entry in an array:
MBS( "JSON.SetPathItem"; "[1,2,3]"; "1"; 5)
Example result:
[1, 5, 3]
Adds an entry to array in object:
MBS( "JSON.SetPathItem"; "{\"test\":[1,2,3]}"; "test¶append"; 5)
Example result:
{
"test": [1, 2, 3, 5]
}
Sets hierarchical item:
MBS( "JSON.SetPathItem"; "{}"; "Hello¶World¶Test"; "Hello" )
Example result:
{
"Hello": {
"World": {
"Test": "Hello"
}
}
}
Create missing array entries and add our new one:
MBS( "JSON.SetPathItem"; "[]"; "5"; "6th item" )
Example result: [null, null, null, null, null, 6]
Try FileMaker syntax to add value to object:
MBS( "JSON.SetPathItem"; "{ \"a\" : 11 }" ; "b" ; "22.23" )
Example result:
{
"a": 11,
"b": 22.23
}
Try FileMaker syntax to add value to array:
MBS( "JSON.SetPathItem"; "[1,2,3]"; "[5]"; 4)
Example result:
[1, 2, 3, null, null, 4]
Try FileMaker syntax to set value in object in an array of an object:
MBS( "JSON.SetPathItem"; "{\"people\":[{\"first\":\"Christian\",\"last\":\"Schmitz\",\"city\":\"Nickenich\"}]}"; "people[0]last"; "test")
Example result:
{
"people": [
{
"first": "Christian",
"last": "test",
"city": "Nickenich"
}
]
}
Try FileMaker syntax to add object to array:
MBS( "JSON.SetPathItem";
"{\"people\":[{\"first\":\"Joe\",\"last\":\"Smith\",\"city\":\"San Francisco\"}]}";
"people[1]";
"{\"first\":\"Peter\",\"last\":\"Miller\",\"city\":\"New York\"}")
Example result:
{
"people": [
{
"first": "Joe",
"last": "Smith",
"city": "San Francisco"
},
{
"first": "Peter",
"last": "Miller",
"city": "New York"
}
]
}
See also
Release notes
- Version 14.3
- Improved JSON.SetPathItem to take the given value as text if it doesn't parse as JSON.
- Version 13.0
- Changed JSON.SetPathItem to do nothing if value is empty (like v12.4 and before).
- Version 12.5
- Fixed a regression in JSON.GetPathItem and JSON.SetPathItem to restore functionality, where you just grab an array item with just an index.
- Version 12.4
- Improved JSON.SetPathItem and JSON.GetPathItem functions to accept FileMaker's style for object/array accessing.
- Version 9.2
- Changed JSON.SetPathItem to create objects if they are missing.
Example Databases
Blog Entries
- MBS FileMaker Plugin, version 14.3pr6
- MBS FileMaker Plugin, version 12.6pr2
- MBS FileMaker Plugin, version 12.5pr4
- MBS FileMaker Plugin, version 12.4pr4
- Recursive Folder Copy Script
- With JSON in excellent form
- MBS FileMaker Plugin, version 9.2pr2
FileMaker Magazin
This function checks for a license.
Created 3th February 2016, last changed 28th August 2022