Skip to main content
typo
Source Link
Stéphane Chazelas
  • 584.5k
  • 96
  • 1.1k
  • 1.7k

Convert the input object to a set of "entires""entries" with to_entries. Each entry is an object with a key key (the key from the object) and a value key (the value of that key in the object).

Pick out the .key and the corresponding .value.remaining value from each entry and put them in an array that you pass through @tsv to output a tab-delimited list.

$ jq -r 'to_entries[] | [.key, .value.remaining] | @tsv' file
T424f7496c3a01  -14889.86
demo    -15030.785

You could read this with IFS=$'\t' read -r the_id remaining in a loop, if you wanted, assuming no keys contained literal tabs, or newlines.


With intermediate results displayed:

$ jq -r 'to_entries[]' file
{
  "key": "T424f7496c3a01",
  "value": {
    "remaining": -14889.86,
    "ts": 136572.504
  }
}
{
  "key": "demo",
  "value": {
    "remaining": -15030.785,
    "ts": 0.515
  }
}
$ jq -r 'to_entries[] | [.key, .value.remaining]' file
[
  "T424f7496c3a01",
  -14889.86
]
[
  "demo",
  -15030.785
]
$ jq -r 'to_entries[] | [.key, .value.remaining] | @tsv' file
T424f7496c3a01  -14889.86
demo    -15030.785

Convert the input object to a set of "entires" with to_entries. Each entry is an object with a key key (the key from the object) and a value key (the value of that key in the object).

Pick out the .key and the corresponding .value.remaining value from each entry and put them in an array that you pass through @tsv to output a tab-delimited list.

$ jq -r 'to_entries[] | [.key, .value.remaining] | @tsv' file
T424f7496c3a01  -14889.86
demo    -15030.785

You could read this with IFS=$'\t' read -r the_id remaining in a loop, if you wanted, assuming no keys contained literal tabs, or newlines.


With intermediate results displayed:

$ jq -r 'to_entries[]' file
{
  "key": "T424f7496c3a01",
  "value": {
    "remaining": -14889.86,
    "ts": 136572.504
  }
}
{
  "key": "demo",
  "value": {
    "remaining": -15030.785,
    "ts": 0.515
  }
}
$ jq -r 'to_entries[] | [.key, .value.remaining]' file
[
  "T424f7496c3a01",
  -14889.86
]
[
  "demo",
  -15030.785
]
$ jq -r 'to_entries[] | [.key, .value.remaining] | @tsv' file
T424f7496c3a01  -14889.86
demo    -15030.785

Convert the input object to a set of "entries" with to_entries. Each entry is an object with a key key (the key from the object) and a value key (the value of that key in the object).

Pick out the .key and the corresponding .value.remaining value from each entry and put them in an array that you pass through @tsv to output a tab-delimited list.

$ jq -r 'to_entries[] | [.key, .value.remaining] | @tsv' file
T424f7496c3a01  -14889.86
demo    -15030.785

You could read this with IFS=$'\t' read -r the_id remaining in a loop, if you wanted, assuming no keys contained literal tabs, or newlines.


With intermediate results displayed:

$ jq -r 'to_entries[]' file
{
  "key": "T424f7496c3a01",
  "value": {
    "remaining": -14889.86,
    "ts": 136572.504
  }
}
{
  "key": "demo",
  "value": {
    "remaining": -15030.785,
    "ts": 0.515
  }
}
$ jq -r 'to_entries[] | [.key, .value.remaining]' file
[
  "T424f7496c3a01",
  -14889.86
]
[
  "demo",
  -15030.785
]
$ jq -r 'to_entries[] | [.key, .value.remaining] | @tsv' file
T424f7496c3a01  -14889.86
demo    -15030.785
added 28 characters in body
Source Link
muru
  • 77.9k
  • 16
  • 212
  • 317

Convert the input object to a set of "entires" with to_entries. Each entry is an object with a key key (the key from the object) and a value key (the value of that key in the object).

Pick out the .key and the corresponding .value.remaining value from each entry and put them in an array that you pass through @tsv to output a tab-delimited list.

$ jq -r 'to_entries[] | [.key, .value.remaining] | @tsv' file
T424f7496c3a01  -14889.86
demo    -15030.785
$ jq -r 'to_entries[] | [.key, .value.remaining] | @tsv' file
T424f7496c3a01  -14889.86
demo    -15030.785

You could read this with IFS=$'\t' read -r the_id remaining in a loop, if you wanted, assuming no keys contained literal tabs, or newlines.


With intermediate results displayed:

$ jq -r 'to_entries[]' file
{
  "key": "T424f7496c3a01",
  "value": {
    "remaining": -14889.86,
    "ts": 136572.504
  }
}
{
  "key": "demo",
  "value": {
    "remaining": -15030.785,
    "ts": 0.515
  }
}
$ jq -r 'to_entries[]' file
{
  "key": "T424f7496c3a01",
  "value": {
    "remaining": -14889.86,
    "ts": 136572.504
  }
}
{
  "key": "demo",
  "value": {
    "remaining": -15030.785,
    "ts": 0.515
  }
}
$ jq -r 'to_entries[] | [.key, .value.remaining]' file
[
  "T424f7496c3a01",
  -14889.86
]
[
  "demo",
  -15030.785
]
$ jq -r 'to_entries[] | [.key, .value.remaining]' file
[
  "T424f7496c3a01",
  -14889.86
]
[
  "demo",
  -15030.785
]
$ jq -r 'to_entries[] | [.key, .value.remaining] | @tsv' file
T424f7496c3a01  -14889.86
demo    -15030.785
$ jq -r 'to_entries[] | [.key, .value.remaining] | @tsv' file
T424f7496c3a01  -14889.86
demo    -15030.785

Convert the input object to a set of "entires" with to_entries. Each entry is an object with a key key (the key from the object) and a value key (the value of that key in the object).

Pick out the .key and the corresponding .value.remaining value from each entry and put them in an array that you pass through @tsv to output a tab-delimited list.

$ jq -r 'to_entries[] | [.key, .value.remaining] | @tsv' file
T424f7496c3a01  -14889.86
demo    -15030.785

You could read this with IFS=$'\t' read -r the_id remaining in a loop, if you wanted, assuming no keys contained literal tabs, or newlines.


With intermediate results displayed:

$ jq -r 'to_entries[]' file
{
  "key": "T424f7496c3a01",
  "value": {
    "remaining": -14889.86,
    "ts": 136572.504
  }
}
{
  "key": "demo",
  "value": {
    "remaining": -15030.785,
    "ts": 0.515
  }
}
$ jq -r 'to_entries[] | [.key, .value.remaining]' file
[
  "T424f7496c3a01",
  -14889.86
]
[
  "demo",
  -15030.785
]
$ jq -r 'to_entries[] | [.key, .value.remaining] | @tsv' file
T424f7496c3a01  -14889.86
demo    -15030.785

Convert the input object to a set of "entires" with to_entries. Each entry is an object with a key key (the key from the object) and a value key (the value of that key in the object).

Pick out the .key and the corresponding .value.remaining value from each entry and put them in an array that you pass through @tsv to output a tab-delimited list.

$ jq -r 'to_entries[] | [.key, .value.remaining] | @tsv' file
T424f7496c3a01  -14889.86
demo    -15030.785

You could read this with IFS=$'\t' read -r the_id remaining in a loop, if you wanted, assuming no keys contained literal tabs, or newlines.


With intermediate results displayed:

$ jq -r 'to_entries[]' file
{
  "key": "T424f7496c3a01",
  "value": {
    "remaining": -14889.86,
    "ts": 136572.504
  }
}
{
  "key": "demo",
  "value": {
    "remaining": -15030.785,
    "ts": 0.515
  }
}
$ jq -r 'to_entries[] | [.key, .value.remaining]' file
[
  "T424f7496c3a01",
  -14889.86
]
[
  "demo",
  -15030.785
]
$ jq -r 'to_entries[] | [.key, .value.remaining] | @tsv' file
T424f7496c3a01  -14889.86
demo    -15030.785
deleted 10 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Convert the input object to a set of "entires" with to_entries. Each entry is an object with a key key (the key from the object) and a value key (the value of that key in the object).

Pick out the .key and the corresponding .value.remaining value from each entry and put them in an array that you pass through @tsv to output a tab-delimited list.

$ jq -r 'to_entries[] | [.key, .value.remaining] | @tsv' file
T424f7496c3a01  -14889.86
demo    -15030.785

You could read this with IFS=$'\t' read -r the_id remaining in a loop, if you wanted, assuming no keys or values contained literal tabs, or newlines.


With intermediate results displayed:

$ jq -r 'to_entries[]' file
{
  "key": "T424f7496c3a01",
  "value": {
    "remaining": -14889.86,
    "ts": 136572.504
  }
}
{
  "key": "demo",
  "value": {
    "remaining": -15030.785,
    "ts": 0.515
  }
}
$ jq -r 'to_entries[] | [.key, .value.remaining]' file
[
  "T424f7496c3a01",
  -14889.86
]
[
  "demo",
  -15030.785
]
$ jq -r 'to_entries[] | [.key, .value.remaining] | @tsv' file
T424f7496c3a01  -14889.86
demo    -15030.785

Convert the input object to a set of "entires" with to_entries. Each entry is an object with a key key (the key from the object) and a value key (the value of that key in the object).

Pick out the .key and the corresponding .value.remaining value from each entry and put them in an array that you pass through @tsv to output a tab-delimited list.

$ jq -r 'to_entries[] | [.key, .value.remaining] | @tsv' file
T424f7496c3a01  -14889.86
demo    -15030.785

You could read this with IFS=$'\t' read -r the_id remaining in a loop, if you wanted, assuming no keys or values contained literal tabs, or newlines.


With intermediate results displayed:

$ jq -r 'to_entries[]' file
{
  "key": "T424f7496c3a01",
  "value": {
    "remaining": -14889.86,
    "ts": 136572.504
  }
}
{
  "key": "demo",
  "value": {
    "remaining": -15030.785,
    "ts": 0.515
  }
}
$ jq -r 'to_entries[] | [.key, .value.remaining]' file
[
  "T424f7496c3a01",
  -14889.86
]
[
  "demo",
  -15030.785
]
$ jq -r 'to_entries[] | [.key, .value.remaining] | @tsv' file
T424f7496c3a01  -14889.86
demo    -15030.785

Convert the input object to a set of "entires" with to_entries. Each entry is an object with a key key (the key from the object) and a value key (the value of that key in the object).

Pick out the .key and the corresponding .value.remaining value from each entry and put them in an array that you pass through @tsv to output a tab-delimited list.

$ jq -r 'to_entries[] | [.key, .value.remaining] | @tsv' file
T424f7496c3a01  -14889.86
demo    -15030.785

You could read this with IFS=$'\t' read -r the_id remaining in a loop, if you wanted, assuming no keys contained literal tabs, or newlines.


With intermediate results displayed:

$ jq -r 'to_entries[]' file
{
  "key": "T424f7496c3a01",
  "value": {
    "remaining": -14889.86,
    "ts": 136572.504
  }
}
{
  "key": "demo",
  "value": {
    "remaining": -15030.785,
    "ts": 0.515
  }
}
$ jq -r 'to_entries[] | [.key, .value.remaining]' file
[
  "T424f7496c3a01",
  -14889.86
]
[
  "demo",
  -15030.785
]
$ jq -r 'to_entries[] | [.key, .value.remaining] | @tsv' file
T424f7496c3a01  -14889.86
demo    -15030.785
added 7 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
Loading
deleted 24 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
Loading
added 136 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
Loading
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
Loading