Skip to content

Instantly share code, notes, and snippets.

@garyb
Created November 24, 2017 18:02
Show Gist options
  • Save garyb/6ffc22924376c59ef28b128660371ae8 to your computer and use it in GitHub Desktop.
Save garyb/6ffc22924376c59ef28b128660371ae8 to your computer and use it in GitHub Desktop.
Structure edits
{ "a": 1, "b": { "ba": { "innermost": true }, "bb": ["x", false, { "foo": "bar" }], "bc": 0.5 }, "c": [] }
{ "a": 2, "b": { "ba": { "innermost": false }, "bb": ["y", true, { "foo": "baz" }], "bc": 60 }, "c": [true, false, "maybe"] }
{ "a": 3, "b": { "ba": true, "bb": ["z", { "foo": "quux" }] }, "c": null }
  1. Un-nest t0.b.ba.innermost
  2. Relabel t0.b.innermost to "bd"
  3. Nest key t0.c under "b"
  4. Relabel t0.b.c to "be"
SELECT MAP_CONCAT(t3, {"b": MAP_CONCAT(DELETE_KEY(t3.b, "c"), {"be": MAP_CONCAT(t3.b.be, t3.b.c) ?? t3.b.c}) ?? t3.b}) ?? t3 FROM (SELECT MAP_CONCAT(DELETE_KEY(t2, "c"), {"b": MAP_CONCAT(t2.b, {"c": MAP_CONCAT(t2.b.c, t2.c) ?? t2.c}) ?? {"c": t2.c}}) ?? t2 FROM (SELECT MAP_CONCAT(t1, {"b": MAP_CONCAT(DELETE_KEY(t1.b, "innermost"), {"bd": MAP_CONCAT(t1.b.bd, t1.b.innermost) ?? t1.b.innermost}) ?? t1.b}) ?? t1 FROM (SELECT MAP_CONCAT(t0, {"b": MAP_CONCAT(DELETE_KEY(t0.b, "ba"), {"ba": DELETE_KEY(t0.b.ba, "innermost") ?? t0.b.ba, "innermost": MAP_CONCAT(t0.b.innermost, t0.b.ba.innermost) ?? t0.b.ba.innermost}) ?? t0.b}) ?? t0 FROM :resource AS t0) AS t1) AS t2) AS t3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment