Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Function

unflatten — transform an array of key/value records into a record

Synopsis

unflatten(val: [{key:string|[string],value:any}]) -> record

Description

The unflatten function converts the key/value records in array val into a single record. unflatten is the inverse of flatten, i.e., unflatten(flatten(r)) will produce a record identical to r.

Examples


Unflatten a single simple record

# spq
values unflatten(this)
# input
[{key:"a",value:1},{key:["b"],value:2}]
# expected output
{a:1,b:2}

Flatten to unflatten

# spq
unnest flatten(this) into (
  key[0] != "rm"
  | collect(this)
)
| values unflatten(this)
# input
{a:1,rm:2}
# expected output
{a:1}