Skip to main content Svelte Highlight v7.21.1

jq language preview

1. Filter and transform

select active users, then reshape each entry
horizon-dark
.users
| map(select(.active))
| map({
    id:   .id,
    name: .name,
    tag:  "\(.role)-\(.id)"
  })
atom-one-dark
.users
| map(select(.active))
| map({
    id:   .id,
    name: .name,
    tag:  "\(.role)-\(.id)"
  })
github-dark
.users
| map(select(.active))
| map({
    id:   .id,
    name: .name,
    tag:  "\(.role)-\(.id)"
  })
dracula
.users
| map(select(.active))
| map({
    id:   .id,
    name: .name,
    tag:  "\(.role)-\(.id)"
  })
nord
.users
| map(select(.active))
| map({
    id:   .id,
    name: .name,
    tag:  "\(.role)-\(.id)"
  })
github
.users
| map(select(.active))
| map({
    id:   .id,
    name: .name,
    tag:  "\(.role)-\(.id)"
  })

2. Reduce and group

aggregate order totals per customer
horizon-dark
.orders
| group_by(.customer)
| map({
    customer: .[0].customer,
    total: reduce .[] as $order (0; . + $order.amount)
  })
| sort_by(-.total)
atom-one-dark
.orders
| group_by(.customer)
| map({
    customer: .[0].customer,
    total: reduce .[] as $order (0; . + $order.amount)
  })
| sort_by(-.total)
github-dark
.orders
| group_by(.customer)
| map({
    customer: .[0].customer,
    total: reduce .[] as $order (0; . + $order.amount)
  })
| sort_by(-.total)
dracula
.orders
| group_by(.customer)
| map({
    customer: .[0].customer,
    total: reduce .[] as $order (0; . + $order.amount)
  })
| sort_by(-.total)
nord
.orders
| group_by(.customer)
| map({
    customer: .[0].customer,
    total: reduce .[] as $order (0; . + $order.amount)
  })
| sort_by(-.total)
github
.orders
| group_by(.customer)
| map({
    customer: .[0].customer,
    total: reduce .[] as $order (0; . + $order.amount)
  })
| sort_by(-.total)

3. Errors and format strings

try/catch, env access, and @csv output
horizon-dark
try (
  .records[]
  | select(.score >= 90)
  | [.name, .score, $ENV.REGION]
  | @csv
) catch "error: \(.)"
atom-one-dark
try (
  .records[]
  | select(.score >= 90)
  | [.name, .score, $ENV.REGION]
  | @csv
) catch "error: \(.)"
github-dark
try (
  .records[]
  | select(.score >= 90)
  | [.name, .score, $ENV.REGION]
  | @csv
) catch "error: \(.)"
dracula
try (
  .records[]
  | select(.score >= 90)
  | [.name, .score, $ENV.REGION]
  | @csv
) catch "error: \(.)"
nord
try (
  .records[]
  | select(.score >= 90)
  | [.name, .score, $ENV.REGION]
  | @csv
) catch "error: \(.)"
github
try (
  .records[]
  | select(.score >= 90)
  | [.name, .score, $ENV.REGION]
  | @csv
) catch "error: \(.)"

4. Nested interpolation

a \(...) interpolation containing its own function call
horizon-dark
.items
| map({
    name: .name,
    summary: "\(.name): \(.tags | join(", "))"
  })
atom-one-dark
.items
| map({
    name: .name,
    summary: "\(.name): \(.tags | join(", "))"
  })
github-dark
.items
| map({
    name: .name,
    summary: "\(.name): \(.tags | join(", "))"
  })
dracula
.items
| map({
    name: .name,
    summary: "\(.name): \(.tags | join(", "))"
  })
nord
.items
| map({
    name: .name,
    summary: "\(.name): \(.tags | join(", "))"
  })
github
.items
| map({
    name: .name,
    summary: "\(.name): \(.tags | join(", "))"
  })