From 718f66dfec3a36c29f8e9a84b2a910f0012756e2 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Wed, 19 Aug 2026 15:23:47 +1000 Subject: [PATCH] v4.54.3 --- operators/anchor-and-alias-operators.md | 28 ++++++++--------- operators/divide.md | 4 +-- operators/modulo.md | 4 +-- operators/multiply-merge.md | 6 ++-- operators/recursive-descent-glob.md | 6 ++-- operators/traverse-read.md | 40 ++++++++++++------------- usage/convert.md | 16 ++++++++++ usage/toml.md | 2 +- 8 files changed, 61 insertions(+), 45 deletions(-) diff --git a/operators/anchor-and-alias-operators.md b/operators/anchor-and-alias-operators.md index 97b4ec13..1d33f737 100644 --- a/operators/anchor-and-alias-operators.md +++ b/operators/anchor-and-alias-operators.md @@ -2,7 +2,7 @@ Use the `alias` and `anchor` operators to read and write yaml aliases and anchors. The `explode` operator normalises a yaml file (dereference (or expands) aliases and remove anchor names). -`yq` supports merge aliases (like `<<: *blah`) however this is no longer in the standard yaml spec (1.2) and so `yq` will automatically add the `!!merge` tag to these nodes as it is effectively a custom tag. +`yq` supports merge keys (like `<<: *blah`) from YAML 1.1. These are no longer part of the YAML 1.2 standard, but remain common in practice. Plain `<<:` keys are recognised as merge keys and round-trip as `<<:` without an explicit `!!merge` tag. When the source uses an explicit `!!merge` tag, that is preserved on output. Internally, when `yq` synthesises a `<<` map key (for example during merge operations), it tags the key as `!!merge` rather than `!!str`. ## NOTE --yaml-fix-merge-anchor-to-spec flag @@ -32,7 +32,7 @@ Given a sample.yml file of: r: 10 - &SMALL r: 1 -- !!merge <<: *CENTRE +- <<: *CENTRE r: 10 ``` then @@ -213,10 +213,10 @@ item_value: &item_value value: true thingOne: name: item_1 - !!merge <<: *item_value + <<: *item_value thingTwo: name: item_2 - !!merge <<: *item_value + <<: *item_value ``` then ```bash @@ -231,7 +231,7 @@ thingOne: value: false thingTwo: name: item_2 - !!merge <<: *item_value + <<: *item_value ``` ## LEGACY: Explode with merge anchors @@ -249,13 +249,13 @@ bar: &bar c: bar_c foobarList: b: foobarList_b - !!merge <<: + <<: - *foo - *bar c: foobarList_c foobar: c: foobar_c - !!merge <<: *foo + <<: *foo thing: foobar_thing ``` then @@ -298,7 +298,7 @@ Given a sample.yml file of: r: 10 - &SMALL r: 1 -- !!merge <<: +- <<: - *CENTRE - *BIG ``` @@ -328,7 +328,7 @@ Given a sample.yml file of: r: 10 - &SMALL r: 1 -- !!merge <<: +- <<: - *BIG - *LEFT - *SMALL @@ -361,13 +361,13 @@ bar: &bar c: bar_c foobarList: b: foobarList_b - !!merge <<: + <<: - *foo - *bar c: foobarList_c foobar: c: foobar_c - !!merge <<: *foo + <<: *foo thing: foobar_thing ``` then @@ -411,7 +411,7 @@ Given a sample.yml file of: r: 10 - &SMALL r: 1 -- !!merge <<: +- <<: - *CENTRE - *BIG ``` @@ -442,7 +442,7 @@ Given a sample.yml file of: r: 10 - &SMALL r: 1 -- !!merge <<: +- <<: - *BIG - *LEFT - *SMALL @@ -467,7 +467,7 @@ Given a sample.yml file of: ```yaml a: b: &b 42 -!!merge <<: +<<: c: *b ``` then diff --git a/operators/divide.md b/operators/divide.md index 6d88949f..62376200 100644 --- a/operators/divide.md +++ b/operators/divide.md @@ -55,7 +55,7 @@ yq '.a = .a / 0 | .b = .b / 0' sample.yml ``` will output ```yaml -a: !!float +Inf -b: !!float -Inf +a: +Inf +b: -Inf ``` diff --git a/operators/modulo.md b/operators/modulo.md index 810f30f3..9e7aa72b 100644 --- a/operators/modulo.md +++ b/operators/modulo.md @@ -34,7 +34,7 @@ yq '.a = .a % .b' sample.yml ``` will output ```yaml -a: !!float 2 +a: 2 b: 2.5 ``` @@ -69,7 +69,7 @@ yq '.a = .a % .b' sample.yml ``` will output ```yaml -a: !!float NaN +a: NaN b: 0 ``` diff --git a/operators/multiply-merge.md b/operators/multiply-merge.md index 368d91fa..2fdb5c6a 100644 --- a/operators/multiply-merge.md +++ b/operators/multiply-merge.md @@ -471,13 +471,13 @@ bar: &bar c: bar_c foobarList: b: foobarList_b - !!merge <<: + <<: - *foo - *bar c: foobarList_c foobar: c: foobar_c - !!merge <<: *foo + <<: *foo thing: foobar_thing ``` then @@ -487,7 +487,7 @@ yq '.foobar * .foobarList' sample.yml will output ```yaml c: foobarList_c -!!merge <<: +<<: - *foo - *bar thing: foobar_thing diff --git a/operators/recursive-descent-glob.md b/operators/recursive-descent-glob.md index cfcb7dae..191fbf80 100644 --- a/operators/recursive-descent-glob.md +++ b/operators/recursive-descent-glob.md @@ -131,13 +131,13 @@ bar: &bar c: bar_c foobarList: b: foobarList_b - !!merge <<: + <<: - *foo - *bar c: foobarList_c foobar: c: foobar_c - !!merge <<: *foo + <<: *foo thing: foobar_thing ``` then @@ -147,7 +147,7 @@ yq '.foobar | [..]' sample.yml will output ```yaml - c: foobar_c - !!merge <<: *foo + <<: *foo thing: foobar_thing - foobar_c - *foo diff --git a/operators/traverse-read.md b/operators/traverse-read.md index d418bc00..f8d80ca9 100644 --- a/operators/traverse-read.md +++ b/operators/traverse-read.md @@ -294,13 +294,13 @@ bar: &bar c: bar_c foobarList: b: foobarList_b - !!merge <<: + <<: - *foo - *bar c: foobarList_c foobar: c: foobar_c - !!merge <<: *foo + <<: *foo thing: foobar_thing ``` then @@ -325,13 +325,13 @@ bar: &bar c: bar_c foobarList: b: foobarList_b - !!merge <<: + <<: - *foo - *bar c: foobarList_c foobar: c: foobar_c - !!merge <<: *foo + <<: *foo thing: foobar_thing ``` then @@ -376,13 +376,13 @@ bar: &bar c: bar_c foobarList: b: foobarList_b - !!merge <<: + <<: - *foo - *bar c: foobarList_c foobar: c: foobar_c - !!merge <<: *foo + <<: *foo thing: foobar_thing ``` then @@ -409,13 +409,13 @@ bar: &bar c: bar_c foobarList: b: foobarList_b - !!merge <<: + <<: - *foo - *bar c: foobarList_c foobar: c: foobar_c - !!merge <<: *foo + <<: *foo thing: foobar_thing ``` then @@ -442,13 +442,13 @@ bar: &bar c: bar_c foobarList: b: foobarList_b - !!merge <<: + <<: - *foo - *bar c: foobarList_c foobar: c: foobar_c - !!merge <<: *foo + <<: *foo thing: foobar_thing ``` then @@ -477,13 +477,13 @@ bar: &bar c: bar_c foobarList: b: foobarList_b - !!merge <<: + <<: - *foo - *bar c: foobarList_c foobar: c: foobar_c - !!merge <<: *foo + <<: *foo thing: foobar_thing ``` then @@ -513,13 +513,13 @@ bar: &bar c: bar_c foobarList: b: foobarList_b - !!merge <<: + <<: - *foo - *bar c: foobarList_c foobar: c: foobar_c - !!merge <<: *foo + <<: *foo thing: foobar_thing ``` then @@ -546,13 +546,13 @@ bar: &bar c: bar_c foobarList: b: foobarList_b - !!merge <<: + <<: - *foo - *bar c: foobarList_c foobar: c: foobar_c - !!merge <<: *foo + <<: *foo thing: foobar_thing ``` then @@ -579,13 +579,13 @@ bar: &bar c: bar_c foobarList: b: foobarList_b - !!merge <<: + <<: - *foo - *bar c: foobarList_c foobar: c: foobar_c - !!merge <<: *foo + <<: *foo thing: foobar_thing ``` then @@ -614,13 +614,13 @@ bar: &bar c: bar_c foobarList: b: foobarList_b - !!merge <<: + <<: - *foo - *bar c: foobarList_c foobar: c: foobar_c - !!merge <<: *foo + <<: *foo thing: foobar_thing ``` then diff --git a/usage/convert.md b/usage/convert.md index 4ad54c7c..9db4c60f 100644 --- a/usage/convert.md +++ b/usage/convert.md @@ -125,6 +125,22 @@ will output {"whatever":"cat"} ``` +## Encode json: preserve floats with trailing zero +Whole-number floats keep their decimal point so downstream consumers see a JSON number with a fractional part (matches Go's encoding/json, Python's json, and jq). + +Given a sample.yml file of: +```yaml +percentiles: [50.0, 95.0, 99.0, 99.9] +``` +then +```bash +yq -o=json -I=0 '.' sample.yml +``` +will output +```json +{"percentiles":[50.0,95.0,99.0,99.9]} +``` + ## Roundtrip JSON Lines / NDJSON Given a sample.json file of: ```json diff --git a/usage/toml.md b/usage/toml.md index dab4abc6..60c4acb5 100644 --- a/usage/toml.md +++ b/usage/toml.md @@ -1,6 +1,6 @@ # TOML -Decode from TOML. Note that `yq` does not yet support outputting in TOML format (and therefore it cannot roundtrip) +Encode and decode to and from TOML. ## Parse: Simple