Flow style writes a collection between brackets and does not use indentation for its structure. It looks like JSON. Every JSON text is YAML 1.2 flow style, and flow collections add unquoted strings, comments and other details.
Flow sequences
A flow sequence is a comma-separated list between square brackets.
primes: [2, 3, 5]
matrix: [[1, 0], [0, 1]]
tags: [one,
two,
three, # comments are allowed here
]
A comma must separate entries, and an empty entry is an error: [a,,b] and
[,a] are both invalid.
Flow mappings
A flow mapping is a comma-separated list of key and value pairs between curly brackets.
position: {x: 1, y: 2}
json: {"name": "value", "n": 1}
adjacent: {"name":"value"}
no-value: {a, b: c}
A key with no value has an empty value. {a, b: c} is a mapping of
two keys, with a mapped to null.
Colons in flow style
A plain key is followed by a colon and white space, or by a colon directly before a
comma or a closing bracket. After a key in double or single quotes, or after a
flow collection used as a key, the value can follow the colon with no space,
which matches JSON: {"a":1}. {a:1} is a plain string
a:1 used as a key with no value.
Explicit keys
? marks a key explicitly, as in block style:
{ ? complex : value, ? [a, b] : c }
Limits on implicit keys
Inside a flow mapping a key may run over several lines. Inside a flow sequence a key of a single-pair mapping must be on one line and at most 1024 characters long.
Single-pair mappings in a sequence
A flow sequence can contain a key and value pair without braces. Each such entry is a mapping of one pair:
short: [a: 1, b, ? c : 2]
long: [{a: 1}, b, {c: 2}]
Plain scalars in flow style
A plain scalar in flow style cannot contain the flow indicators ,
[ ] { }, so
[a b, c] has two entries. See Scalars.
Quoting a value lets it contain them.
Lines and indentation
A flow collection can span lines. Inside one, line breaks act as white space, and a comment can end any line. Its lines are still in the block context around it, so they must be indented further than the parent block collection:
key: [
allowed,
entries
]
keyA closing bracket at the same indentation as key breaks this rule, but many
readers accept it, and so do many files. The explorer lists it as a problem and carries on.
A document marker line cannot appear inside a flow collection. A flow collection does not need a line of its own and can be a value in block style.
Relation to JSON
Since version 1.2, a JSON text is a YAML document: double-quoted strings, numbers,
true, false, null, arrays and objects are all
valid flow style. The relation only goes one way: YAML has features JSON does
not have, so a JSON reader cannot read most YAML. One caution is that a JSON object
with a duplicate key is not a valid YAML mapping, because YAML requires unique keys.
Specification
These rules are in section 7.4 of YAML 1.2.2.