|
| Setting | Default | What it does |
|---|---|---|
nestify.separator |
"." |
Character that joins and splits key paths. |
nestify.indent |
2 |
Spaces used to indent the JSON written back. |
nestify.arrays |
"rebuild" |
Whether nesting rebuilds arrays from index keys. |
nestify.sortKeys |
false |
Write each object's keys in order. |
If your keys already contain dots, set nestify.separator to "/" or "_".
One thing to know about arrays
Flattening an array turns each index into a path segment, so { "tags": ["a"] }
becomes { "tags.0": "a" }, and nesting turns it back into the array it came from.
Keys that are not exactly the indices 0…n-1 — a gap, or "01" — stay an object,
since no array could hold them without inventing values.
The one shape this cannot tell apart is an object whose keys already are "0", "1",
… : it flattens the same way an array does, so it comes back as an array — including
the file itself, which turns from an object into a JSON array when its own top-level
keys are indices. Set nestify.arrays to "objects" if that is your data, and every
container stays an object on the way back.
A key that already contains the separator is refused, because once joined it cannot
be told from a path: flattening { "app": { "v1.2": { "x": 1 } } } would produce
app.v1.2.x, which nests back four levels deep instead of the three that were
written. The refusal names a separator the file leaves free and offers to set it for
you, so one click converts the same file cleanly; nestify.separator takes whatever
character you prefer if you would rather choose it yourself. Keys that clash, contain
an empty segment, or use the reserved name __proto__ are refused too, in both
directions, and the message names the key at fault. Whatever flattens can be nested
back.
Nesting makes the same offer from the other side. A file whose keys are joined with
something other than your separator — a .NET appsettings.json, whose paths use :
and whose last segment is a dotted namespace like
Serilog:MinimumLevel:Override:Microsoft.Extensions.Diagnostics — is refused under
., since the namespace splits and collides with the key beside it. The message
offers the : those keys are actually written with, under which the file nests
cleanly. It works the other way round just as well: with nestify.separator set to
: for those config files, a dot-joined file has no key to split, so rather than
handing it back unchanged Nestify offers the . it is written with. A file that is
already nested has nothing to do under any separator, and converts quietly.
Contributing
Setup, architecture, and how to add a converter live in CONTRIBUTING.md.