TransWikia.com

How does jq work with keys containing slash?

Unix & Linux Asked by fhcat on October 31, 2021

My test json file is as follows:

{
   "server":"xxx",
   "cert":"line1nline2",
   "security/path": "/var/log/systems.log"
}

I would like to filter by key security/path, and below commands all don’t work.

jq .security/path test.json
jq: error: path/0 is not defined at <top-level>, line 1:
.security/path
jq: 1 compile error

jq '.security/path' test.json has same result.

One Answer

From Basic filters:

Object Identifier-Index:

...

If the key contains special characters or starts with a digit, you need to surround it with double quotes like this: ."foo$", or else .["foo$"]

....

So,

$ jq '."security/path"' test.json
"/var/log/systems.log"

Answered by steeldriver on October 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP