Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 919
Saritha Avatar asked Nov 17 '25 03:11

Saritha


1 Answers

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.

like image 132
peak Avatar answered Nov 18 '25 21:11

peak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!