Xbasic
Extension::JsonJsonObjectFlatten Method
Syntax
.JsonObjectFlatten as c (json as C [, separator as C])
Arguments
- jsonCharacter
Json with nested fields we wish to flatten.
- separatorCharacter
Separator to use between parent field and child field names
Description
Flatten subobjects into parent JSON objects - recurses arrays.
Discussion
JsonObjectFlatten recurses into arrays, and flattens nested objects using the field name in the parent, plus a separator to generate a field at the parent object level.
Example
dim json as c = <<%json%
[
{
"CustomerId" : "AMCE" ,
"Contact" : {
"Firstname" : "Sam" ,
"Lastname" : "Clark"
},
"Address" : {
"Street" : "123 Main Street" ,
"City" : "Springfield" ,
"State" : "MI"
}
}
]
%json%
dim out as c = extension::json::JsonObjectFlatten(json,"__")
? out
[
{
"CustomerId": "AMCE",
"Contact__Firstname": "Sam",
"Contact__Lastname": "Clark",
"Address__Street": "123 Main Street",
"Address__City": "Springfield",
"Address__State": "MI"
}
]