
cat ./reg-test/input/flatten-input-1.json
{
  "a": 1,
  "b": {
    "c": 2,
    "d": 3
  }
}
{
  "a": 1,
  "b": {
    "c": {
      "x": 2,
      "y": 3
    },
    "d": {
      "x": 4,
      "y": 5
    }
  }
}
{
  "a": 1,
  "b": {
    "c": [
      2,
      3
    ]
  }
}
{
  "a": 1,
  "b": [
    {
      "x": 2,
      "y": 3
    },
    {
      "x": 4,
      "y": 5
    }
  ]
}

mlr --ijson --oxtab --from ./reg-test/input/flatten-input-1.json put 
  map o = {};
  for (k, v in $*) {
    for (k2, v2 in flatten(k, ".", v)) {
      o[k2] = v2
    }
  }
  $* = o;

b.c 2
b.d 3

b.c.x 2
b.c.y 3
b.d.x 4
b.d.y 5

b.c.1 2
b.c.2 3

b.1.x 2
b.1.y 3
b.2.x 4
b.2.y 5

mlr --ijson --oxtab --from ./reg-test/input/flatten-input-1.json put $* = flatten("", ".", $*)
a   1
b.c 2
b.d 3

a     1
b.c.x 2
b.c.y 3
b.d.x 4
b.d.y 5

a     1
b.c.1 2
b.c.2 3

a     1
b.1.x 2
b.1.y 3
b.2.x 4
b.2.y 5

mlr --ijson --oxtab --from ./reg-test/input/flatten-input-1.json put $* = flatten($*, ".")
a   1
b.c 2
b.d 3

a     1
b.c.x 2
b.c.y 3
b.d.x 4
b.d.y 5

a     1
b.c.1 2
b.c.2 3

a     1
b.1.x 2
b.1.y 3
b.2.x 4
b.2.y 5

mlr --ijson --ojson --no-auto-unflatten --from ./reg-test/input/flatten-input-1.json put $a = flatten("a", ".", $a)
{
  "a": 1,
  "b": {
    "c": 2,
    "d": 3
  }
}
{
  "a": 1,
  "b": {
    "c": {
      "x": 2,
      "y": 3
    },
    "d": {
      "x": 4,
      "y": 5
    }
  }
}
{
  "a": 1,
  "b": {
    "c": [2, 3]
  }
}
{
  "a": 1,
  "b": [
    {
      "x": 2,
      "y": 3
    },
    {
      "x": 4,
      "y": 5
    }
  ]
}

mlr --ijson --ojson --no-auto-unflatten --from ./reg-test/input/flatten-input-1.json put $b = flatten("b", ".", $b)
{
  "a": 1,
  "b": {
    "b.c": 2,
    "b.d": 3
  }
}
{
  "a": 1,
  "b": {
    "b.c.x": 2,
    "b.c.y": 3,
    "b.d.x": 4,
    "b.d.y": 5
  }
}
{
  "a": 1,
  "b": {
    "b.c.1": 2,
    "b.c.2": 3
  }
}
{
  "a": 1,
  "b": {
    "b.1.x": 2,
    "b.1.y": 3,
    "b.2.x": 4,
    "b.2.y": 5
  }
}

mlr --ijson --oxtab --from ./reg-test/input/flatten-input-2.json put $* = flatten("", ".", $*)
hostname                    localhost
pid                         12345
req.id                      6789
req.method                  GET
req.path                    api/check
req.host                    foo.bar
req.headers.host            bar.baz
req.headers.user-agent      browser
res.status_code             200
res.header.content-type     text
res.header.content-encoding plain
empty1                      {}
empty2                      []
wrapper.empty3              {}
wrapper.emtpy4              []

mlr --ixtab --ojson --no-auto-unflatten --from ./reg-test/input/unflatten-input.xtab put $* = unflatten($*, ".")
{
  "hostname": "localhost",
  "pid": 12345,
  "req": {
    "id": 6789,
    "method": "GET",
    "path": "api/check",
    "host": "foo.bar",
    "headers": {
      "host": "bar.baz",
      "user-agent": "browser"
    }
  },
  "res": {
    "status_code": 200,
    "header": {
      "content-type": "text",
      "content-encoding": "plain"
    }
  },
  "empty1": "{}",
  "empty2": "[]",
  "wrapper": {
    "empty3": "{}",
    "emtpy4": "[]"
  }
}

