Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
JSON.Replace
Searches for all values that match the JSONPath expression and replaces them with the specified value.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
JSON | 13.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameters
Parameter | Description | Example |
---|---|---|
json | A JSON text or reference. | "{\"people\":[{\"first\":\"Christian\",\"last\":\"Schmitz\",\"city\":\"Nickenich\"}]}" |
path | The path to query. | "$.books[?(@.title == 'A Wild Sheep Chase')].price" |
ReplaceJSON | The new JSON value. | 123 |
Result
Returns JSON or error.
Description
Searches for all values that match the JSONPath expression and replaces them with the specified value.Returns an error if JSONPath evaluation fails.
See also JSON.Query to just search without replace.
Examples
Find an entry in the books array and change the value:
Let([
json = "{
\"books\": [
{
\"author\": \"Haruki Murakami\",
\"category\": \"fiction\",
\"price\": 20.0,
\"title\": \"A Wild Sheep Chase\"
},
{
\"author\": \"Sergei Lukyanenko\",
\"category\": \"fiction\",
\"price\": 23.58,
\"title\": \"The Night Watch\"
},
{
\"author\": \"Graham Greene\",
\"category\": \"fiction\",
\"price\": 21.99,
\"title\": \"The Comedians\"
},
{
\"author\": \"Phillips, David Atlee\",
\"category\": \"memoir\",
\"title\": \"The Night Watch\"
}
]
}";
output = MBS( "JSON.Replace"; json; "$.books[?(@.title == 'A Wild Sheep Chase')].price"; 123 )
]; output)
Replace null values in object with empty quotes:
MBS( "JSON.Replace"; "{
\"author\": \"test\",
\"category\": null,
\"price\": null,
\"title\": \"test\"
}"; "$..[?(@ == null)]"; "\"\"" )
Example result:
{
"author": "test",
"category": "",
"price": "",
"title": "test"
}
Replace null vaules in array with 0:
MBS( "JSON.Replace"; "[1,2,null,3,4]"; "$..[?(@ == null)]"; "0" )
Example result:
[
1,
2,
0,
3,
4
]
Replace matches using contains:
MBS("JSON.Replace"; "[\"test\", \"abc\", \"ast\"]"; "$[?(contains(@,'s'))]"; "\"match\"")
Example result:
[
"match",
"abc",
"match"
]
See also
- JSON.CurrentMatch
- JSON.CurrentMatchPath
- JSON.InsertOrUpdateRecord
- JSON.InsertRecord
- JSON.Query
- JSON.Release
- JSON.ReplaceEvaluate
- JSON.ReplaceItemInArray
- JSON.ReplaceItemInObject
Release notes
- Version 14.4
- Improved JSON functions to return error if you pass non JSON parameters to JSON.AddItemToArray, JSON.AddItemToObject, JSON.Replace and related functions.
- Version 14.2
- Added JSON.ReplaceEvaluate function and related JSON.CurrentMatch and JSON.CurrentMatchPath functions.
- Version 14.1
- Changed JSON.Replace to accept text or number as replacement and convert it to JSON internally automatically instead of returning a parsing error.
- Fixed an edge case with JSON.Replace where it didn't catch all spots.
- Version 13.5
- Added JSON.Replace to replace within a JSON.
Example Databases
Blog Entries
- MBS FileMaker Plugin, version 14.4pr6
- MBS Plugin 14.2 for Claris FileMaker
- JSON Replace with evaluate
- MBS Plugin 14.1 for Claris FileMaker
- MBS FileMaker Plugin, version 14.1pr5
- MBS FileMaker Plugin, version 14.1pr3
- New in MBS FileMaker Plugin 13.5
- MBS Plugin 13.5 for Claris FileMaker
- Using JSONPath in FileMaker
- Checking out JSON.Search function in MBS FileMaker Plugin
FileMaker Magazin
This function checks for a license.
Created 17th September 2023, last changed 22nd July 2024