>_ IzzyLab

Hands-on task

This task is step 11 of the course “JSON, YAML and XML in the terminal”

jq: merge two objects

medium~5 min

There is a base config /root/base.json and overrides /root/override.json. Merge them into a single object so that values from override.json win on key conflicts, and write the result to /root/merged.json.

What you'll practise:
  • jq
  • json merge
  • recursive merge
  • slurp
  • configs

Topic breakdown

Applying overrides on top of a base config is a typical task when working with settings: you take the common values and selectively override them per environment. In jq two objects can be merged recursively, and on a key conflict the operand on a certain side wins — so the outcome depends entirely on the order of operands. To make both input documents available to a single filter, they are "slurped" into a common array (slurp mode), after which the elements of that array are combined.

What's checked

  1. objects merged, override won

What it looks like