Data structure examples
Scalars
String
Input (a.json):
Read a string field:
Stdout: "alice"
Set a string field:
Stdout:
Integer
Input:
Set:
Stdout: {"count":42}
Increment with |=:
Stdout: {"count":1}
Float
Input:
Stdout: {"ratio":1.25}
Boolean
Input:
Stdout: {"enabled":true}
Null
Input:
Set a field to null:
Stdout: {"key":null}
Warning
TOML cannot represent null. Setting a field to null in a TOML file is an error:
Nested objects
Input (config.json):
Deep key access:
Stdout: 30
Nested mutation:
Stdout:
Partial update (preserves sibling keys):
Stdout:
Arrays
Input (data.json):
Index access:
Stdout: 10
Update by index:
Stdout: {"items":[10,20,99,40,50]}
Map over all elements (.[]=|= ...):
Stdout: {"items":[20,40,60,80,100]}
Append an element:
Stdout: {"items":[10,20,30,40,50,99]}
Delete by index:
Stdout: {"items":[10,30,40,50]}
Filter with select
select(predicate) keeps only elements for which the predicate is true. Wrap with array reconstruction to filter an array-of-maps:
Input (services.yaml):
Stdout:
Key order within each map entry is preserved. The worker entry is dropped because .enabled == false.
Array-of-maps
Input (pods.yaml):
pods:
- name: web
replicas: 1
image: nginx
- name: worker
replicas: 2
image: python
- name: cache
replicas: 1
image: redis
Update the first element:
Stdout:
pods:
- name: web
replicas: 3
image: nginx
- name: worker
replicas: 2
image: python
- name: cache
replicas: 1
image: redis
Key order within each map entry is preserved.
Note
Positional reconciliation: When a jq expression reshapes an array (e.g., sort_by, reverse), each output element inherits key order from the element at the same positional index in the input. This is deterministic but may produce surprising key orderings if the array is reordered. This is a documented v1 behaviour (DR-007).
Mixed-depth structures
Input (mixed.json):
Access array inside nested object:
Stdout: "b"
Mutate deep inside:
Stdout:
YAML 1.1 vs 1.2 booleans
YAML 1.2 (the default) only recognises true and false as booleans. Values like yes, no, on, and off are plain strings.
Input (flags.yaml):
Default (YAML 1.2 — yes is a string):
Stdout: yes
With --yaml-version 1.1 — yes is decoded as boolean true:
Stdout: true
Stdout: false
Stdout: true
Note
The encoder always writes YAML 1.2 output regardless of --yaml-version. Setting --yaml-version 1.1 only affects how the input is decoded.
Available in v1
The --yaml-version flag was included in v1 scope despite appearing in the RFC's deferral list. It is fully supported.
TOML-specific types
Integer vs float
TOML distinguishes integers from floats at the type level. nesdit preserves this distinction:
Input (nums.toml):
Update the integer:
Stdout: count = 100\nratio = 3.14
Update to a float:
Stdout: count = 42\nratio = 2.718
Inline tables
nesdit emits TOML nested objects as inline tables to preserve key order. Input with [section] syntax is read correctly:
Input (project.toml):
Stdout:
The [section] input was read; the output uses inline-table syntax. Round-trips are byte-stable: running the same command again on this output produces byte-identical output.