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
MBS( "JSON.Replace"; json; path; ReplaceJSON )   More

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)

See also

Release notes

  • 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.
  • Version 13.5

Example Databases

Blog Entries

This function checks for a license.

Created 17th September 2023, last changed 13th October 2023


JSON.ReleaseAll - JSON.ReplaceItemInArray

💬 Ask a question or report a problem