jsonyq

Why do I get twice the same JSON output with mikefarah/yq?


I have installed mikefarah/yq :

$ yq -V
yq (https://github.com/mikefarah/yq/) version v4.44.3
$

I want to create a JSON structure with yq.

I tried this yq command :

yq -n -o=json '.a = 1,.b.c = 16 , .b.d = 12'

But I get this JSON output :

{
  "a": 1,
  "b": {
    "c": 16,
    "d": 12
  }
}
{
  "a": 1,
  "b": {
    "c": 16,
    "d": 12
  }
}

I expect this :

{
  "a": 1,
  "b": {
    "c": 16,
    "d": 12
  }
}

Solution

  • , opens another context. Pipe into a new filter using | to modify the same context:

    yq -n -o=json '.a = 1 | .b.c = 16 | .b.d = 12'
    
    {
      "a": 1,
      "b": {
        "c": 16,
        "d": 12
      }
    }