admin管理员组

文章数量:1123107

I have installed mikefarah/yq :

$ yq -V
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
  }
}

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
  }
}
Share Improve this question asked 5 hours ago SebMaSebMa 4,65936 silver badges48 bronze badges 1
  • The only thing that's at all surprising here is that you have the output twice instead of three times, given the three comma-separated expressions. – Charles Duffy Commented 3 hours ago
Add a comment  | 

1 Answer 1

Reset to default 2

, 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
  }
}

本文标签: Why do I get twice the same JSON output with mikefarahyqStack Overflow