twist
twist
function converts a JSON object into another JSON object by twisting it.
Arguments
-
object
type:
object
The JSON object to twist.
-
map
type:
object
The map to twist the JSON object.
e.g.
{ "a.b": "x.y" }
will twist{ a: { b: "c" } }
to{ x: { y: "c" } }
. -
option
type:
object
-
arrayIndex
type:
"dot" | "bracket"
default:
"bracket"
The index of array to twist.
e.g.
{ "a[0]": "x[0]" }
will twist{ a: ["b"] }
to{ x: ["b"] }
ifarrayIndex
is"bracket"
,{ "a.0": "x.0" }
will twist{ a: ["b"] }
to{ x: ["b"] }
ifarrayIndex
is"dot"
. -
pruneArray
type:
boolean
default:
true
Whether to prune the array when twisting.
e.g.
{ "a[0]": "x[1]" }
will twist{ a: ["b"] }
to{ x: [undefined, "b"] }
ifpruneArray
isfalse
,{ "a[0]": "x[1]" }
will twist{ a: ["b"] }
to{ x: ["b"] }
ifpruneArray
istrue
.
-