Treat YAML like JSON for auto-flatten/auto-unflatten (#2196)

* Treat YAML like JSON for auto-flatten/auto-unflatten (#2195)

Auto-flatten/unflatten decisions only checked for "json", so nested
data written to YAML was needlessly flattened and non-JSON data
converted to YAML was never unflattened into arrays/maps. Both formats
support native nesting, so both should be treated the same way.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* Clarify why DCF is excluded from auto-flatten separately from JSON/YAML

DCF isn't a nestable format like JSON/YAML -- it just has its own
hardcoded comma-list serialization for a fixed set of field names
that generic key-spreading flatten would clobber. Split the comment
so that distinction isn't lost.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* Refer to JSON/YAML throughout the flatten-unflatten doc

The summary paragraph calling out YAML as an aside did not read
naturally next to prose that otherwise only said JSON. Fold YAML
into the headings and body text directly instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
John Kerl 2026-07-15 10:15:33 -04:00 committed by GitHub
parent a112f1f112
commit 6a38408bb3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 136 additions and 83 deletions

View file

@ -458,7 +458,7 @@
csv` is the same as `--ocsv`.
1mFLATTEN-UNFLATTEN FLAGS0m
These flags control how Miller converts record values which are maps or arrays, when input is JSON and output is non-JSON (flattening) or input is non-JSON and output is JSON (unflattening).
These flags control how Miller converts record values which are maps or arrays, when input is JSON/YAML and output is not (flattening) or input is not JSON/YAML and output is JSON/YAML (unflattening).
See the flatten/unflatten doc page https://miller.readthedocs.io/en/latest/flatten-unflatten for more information.
@ -466,16 +466,17 @@
Separator for flattening multi-level JSON keys, e.g.
`{"a":{"b":3}}` becomes `a:b => 3` for non-JSON
formats. Defaults to `.`.
--no-auto-flatten When output is non-JSON, suppress the default
--no-auto-flatten When output is not JSON or YAML, suppress the default
auto-flatten behavior. Default: if `$y = [7,8,9]`
then this flattens to `y.1=7,y.2=8,y.3=9`, and
similarly for maps. With `--no-auto-flatten`, instead
we get `$y=[1, 2, 3]`.
--no-auto-unflatten When input is non-JSON and output is JSON, suppress
the default auto-unflatten behavior. Default: if the
input has `y.1=7,y.2=8,y.3=9` then this unflattens to
`$y=[7,8,9]`. With `--no-auto-flatten`, instead we
get `${y.1}=7,${y.2}=8,${y.3}=9`.
--no-auto-unflatten When input is not JSON or YAML and output is JSON or
YAML, suppress the default auto-unflatten behavior.
Default: if the input has `y.1=7,y.2=8,y.3=9` then
this unflattens to `$y=[7,8,9]`. With
`--no-auto-flatten`, instead we get
`${y.1}=7,${y.2}=8,${y.3}=9`.
1mFORMAT-CONVERSION KEYSTROKE-SAVER FLAGS0m
As keystroke-savers for format-conversion you may use the following.
@ -4138,4 +4139,4 @@
MIME Type for Comma-Separated Values (CSV) Files, the Miller docsite
https://miller.readthedocs.io
2026-07-14 4mMILLER24m(1)
2026-07-15 4mMILLER24m(1)

View file

@ -2,12 +2,12 @@
.\" Title: mlr
.\" Author: [see the "AUTHOR" section]
.\" Generator: ./mkman.rb
.\" Date: 2026-07-14
.\" Date: 2026-07-15
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "MILLER" "1" "2026-07-14" "\ \&" "\ \&"
.TH "MILLER" "1" "2026-07-15" "\ \&" "\ \&"
.\" -----------------------------------------------------------------
.\" * Portability definitions
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -554,7 +554,7 @@ are overridden in all cases by setting output format to `format2`.
.RS 0
.\}
.nf
These flags control how Miller converts record values which are maps or arrays, when input is JSON and output is non-JSON (flattening) or input is non-JSON and output is JSON (unflattening).
These flags control how Miller converts record values which are maps or arrays, when input is JSON/YAML and output is not (flattening) or input is not JSON/YAML and output is JSON/YAML (unflattening).
See the flatten/unflatten doc page https://miller.readthedocs.io/en/latest/flatten-unflatten for more information.
@ -562,16 +562,17 @@ See the flatten/unflatten doc page https://miller.readthedocs.io/en/latest/flatt
Separator for flattening multi-level JSON keys, e.g.
`{"a":{"b":3}}` becomes `a:b => 3` for non-JSON
formats. Defaults to `.`.
--no-auto-flatten When output is non-JSON, suppress the default
--no-auto-flatten When output is not JSON or YAML, suppress the default
auto-flatten behavior. Default: if `$y = [7,8,9]`
then this flattens to `y.1=7,y.2=8,y.3=9`, and
similarly for maps. With `--no-auto-flatten`, instead
we get `$y=[1, 2, 3]`.
--no-auto-unflatten When input is non-JSON and output is JSON, suppress
the default auto-unflatten behavior. Default: if the
input has `y.1=7,y.2=8,y.3=9` then this unflattens to
`$y=[7,8,9]`. With `--no-auto-flatten`, instead we
get `${y.1}=7,${y.2}=8,${y.3}=9`.
--no-auto-unflatten When input is not JSON or YAML and output is JSON or
YAML, suppress the default auto-unflatten behavior.
Default: if the input has `y.1=7,y.2=8,y.3=9` then
this unflattens to `$y=[7,8,9]`. With
`--no-auto-flatten`, instead we get
`${y.1}=7,${y.2}=8,${y.3}=9`.
.fi
.if n \{\
.RE