Xbasic
json_delete Function
Syntax
C result = json_delete(json as C, pattern as C)
Arguments
- jsonCharacter
Json to filter nested records from.
- patternCharacter
Pattern to match for deletion.
Description
Remove any nested array member that matches pattern.
Deletes attributes from a JSON string that match a certain pattern. For example, consider the following JSON string:
dim json as c = <<%json%
{
one : 1 ,
two : 2 ,
arr : [
{ __deleted : true , fname : "joe" },
{ __deleted : false , fname : "jim" }
],
arr2 : [
{ __deleted : false , fname : "joe" },
{ __deleted : true , fname : "jim" }
],
}
%json%Assume that you want to remove all 'rows' in the JSON that contain the attribute:
__deleted: true
Using json_delete() we can do this:
json = json_sanitize(json) 'convert to strict syntax
dim json2 as c
json2 = json_delete(json , "{ \"__deleted\" : true }")
json2 = json_reformat(json2)
?json2
= {
"one": 1,
"two": 2,
"arr": [
{
"__deleted": false,
"fname": "jim"
}
],
"arr2": [
{
"__deleted": false,
"fname": "joe"
}
]
}