Unflatten dictionary [JS1]

A JavaScript one-liner to convert a flattened dictionary to a nested one


Description

A single line of JavaScript to convert a (totally or partially) flattened dictionary to a nested one where the keys correspond to the parts of the original keys interpreted as dot-notation "paths".

The shortcut works as a function, expecting a dictionary's JSON representation as parameter. If no input is provided the shortcut works as a demo and shows the output at the end. The example included is the dictionary

{
  "a.b.c": 1,
  "a.b.d": 2,
  "a.e.f": "😎"
}

that is transformed to

{
  "a": {
    "b": {
      "c": 1,
      "d": 2
    },
    "e": {
      "f": "😎"
    }
  }
}

The reverse conversion can be found in my Flatten dictionary [JS1] shortcut.

This shortcut uses the improved method to run JavaScript inside a shortcut by @gluebyte.


Latest Release Notes

1.0.2 - July 7, 2023, 6:30 a.m.

Fixed emoji encoding issue (thanks to Ritter3435 at Discord for the heads up)


Version history