Saritha
Saritha

Reputation: 235

how to restrict indentation while using jq filters on json file

My input JSON file is:

{
    "name": "abc",
    "private": true,
    "version": "1.0.0",
    "description": "UI",
    "dependencies": {
        "xyz": "9.11",
        "abc": "5.0.0"
    }
}

When I use jq .name=xyz, the output will be printed as:

{
  "name": "xyz",
  "private": true,
  "version": "1.0.0",
  "description": "UI",
  "dependencies": {
    "xyz": "9.11",
    "abc": "5.0.0"
  }
}

Though my input file as proper indentation, after running the jq command the indentation is different.
How can I restrict the indentation?

Thanks in advance!

Upvotes: 22

Views: 8787

Answers (1)

peak
peak

Reputation: 116780

There is currently no way to instruct jq to preserve the indentation style per se, but the --indent N and --tab command-line options give limited control over the style of indentation. Thus, in the particular case given, one could achieve the desired effect using --indent 4.

Upvotes: 30

Related Questions