Skip to content

Commit

Permalink
Add slurpfile example
Browse files Browse the repository at this point in the history
  • Loading branch information
nntrn committed Feb 29, 2024
1 parent 5d07a48 commit b114d7d
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions general/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,58 @@ $ jq '.[] |= if .attr2 then (.attr2 = "bax") else . end'
```

[[Source]](https://github.com/stedolan/jq/issues/873#issuecomment-125385615)


## Slurpfiles

```console
$ jq --slurpfile cars data/cars.json '{titanic: .[0:2],cars:$cars[][0:2]}' data/titanic.json
{
"titanic": [
{
"Survived": 0,
"Pclass": 3,
"Name": "Mr. Owen Harris Braund",
"Sex": "male",
"Age": 22,
"Siblings_Spouses_Aboard": 1,
"Parents_Children_Aboard": 0,
"Fare": 7.25
},
{
"Survived": 1,
"Pclass": 1,
"Name": "Mrs. John Bradley (Florence Briggs Thayer) Cumings",
"Sex": "female",
"Age": 38,
"Siblings_Spouses_Aboard": 1,
"Parents_Children_Aboard": 0,
"Fare": 71.2833
}
],
"cars": [
{
"name": "AMC Ambassador Brougham",
"brand": "AMC",
"economy_mpg_": 13,
"cylinders": 8,
"displacement_cc_": 360,
"power_hp_": 175,
"weight_lb_": 3821,
"0_60_mph_s_": 11,
"year": 1973
},
{
"name": "AMC Ambassador DPL",
"brand": "AMC",
"economy_mpg_": 15,
"cylinders": 8,
"displacement_cc_": 390,
"power_hp_": 190,
"weight_lb_": 3850,
"0_60_mph_s_": 8.5,
"year": 1970
}
]
}
```

0 comments on commit b114d7d

Please sign in to comment.