简体   繁体   中英

Get key names from JSON file recursively using jq

I can get top-level JSON keys with jq as

jq 'keys'

Eg, see this question: Get key names from JSON file using jq

And I can enable recursion in jq :

jq '..'

As in: Recursive search values by key

But jq '.. | keys' jq '.. | keys' returns jq: error at <stdin> string has no keys .

当 JSON 中的某些值不存在键时,只需忽略键:

jq '.. | keys?'

Ignore non-objects when inspecting for key names:

jq -r '.. | if type == "object" then to_entries[] | .key else empty end' "${LOCALAPPDATA}/Google/Chrome/User Data/default/Bookmarks" | sort --uniq
bookmark_bar
checksum
children
date_added
date_modified
guid
id
name
other
roots
synced
type
url
version

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM