created: 20231204112944341
modified: 20231204115056732
tags: [[Operator Examples]] [[jsonset Operator]]
title: jsonset Operator (Examples)
<$let object-a="""{
"a": "one",
"b": "",
"c": "three",
"d": {
"e": "four",
"f": [
"five",
"six",
true,
false,
null
],
"g": {
"x": "max",
"y": "may",
"z": "maize"
}
}
}
"""
object-b="""{"a":"one","b":"","c":1.618,"d":{"e":"four","f":["five","six",true,false,null]}}""">
The examples below assume the following JSON object is contained in the variable `object-a`:
<>
<<.operator-example 1 "[jsonset[d],[Jaguar]]">>
<<.operator-example 2 "[jsonset[d],[f],[Panther]]">>
<<.operator-example 3 "[jsonset[d],[f],[-1],[Elephant]]">>
<<.operator-example 4 "[jsonset[d],[f],[-2],[Elephant]]">>
<<.operator-example 5 "[jsonset[d],[f],[-4],[Elephant]]">>
<<.operator-example 6 "[jsonset[Panther]]" "If only a single parameter is specified, it replaces the entire JSON object">>
<<.operator-example 7 "[jsonset[]]" "If only a single blank parameter is specified, no changes are made to the JSON object">>
The examples below assume the following JSON object is contained in the variable `object-b`:
<>
<<.operator-example 8 "[jsonset[]]" "If only a single blank parameter is specified, no changes are made to the JSON object">>
<<.operator-example 9 "[jsonset[],[Antelope]]" "If the property to be set is blank, the entire JSON object is replaced">>
<<.operator-example 10 "[jsonset:number[],[not a number]]" "invalid numbers are interpreted as zero">>
<<.operator-example 11 "[jsonset[id],[Antelope]]" "nonexistent top level properties are added to the object">>
<<.operator-example 19 "[jsonset[missing],[id],[Antelope]]" "nonexistent nested properties are are ignored">>
<<.operator-example 12 "[jsonset:notatype[id],[Antelope]]" "invalid type suffix is interpreted as the default string type">>
<<.operator-example 13 "[jsonset:boolean[id],[false]]">>
<<.operator-example 14 "[jsonset:boolean[id],[Antelope]]" "invalid boolean value causes no assignment to be made">>
<<.operator-example 15 "[jsonset:number[id],[42]]">>
<<.operator-example 16 "[jsonset:null[id]]">>
<<.operator-example 17 "[jsonset:array[d],[f],[5]]">>
<<.operator-example 18 "[jsonset:object[d],[f],[5]]">>
<<.operator-example 20 "[] [] :and[jsonset[b],[two]]" "If the input consists of multiple JSON objects with matching properties, the value is set for all of them">>