Extracting Specific Fields from JSON
When extracting values from JSON with fx, strings are printed as raw text by default. To get properly quoted JSON output, you can append JSON.stringify as a second argument.
Single Field
bash
cat data.json | fx .user.nameOutput:
json
"Alice"Multiple Fields
bash
cat data.json | fx '{name: x.user.name, email: x.user.email}'Output:
json
{
"name": "Alice",
"email": "alice@example.com"
}From an Array of Objects
bash
cat users.json | fx 'map(u => u.name)'Output:
json
[
"Alice",
"Bob"
]