https://github.com/cdown/json-key-from-value
Find the key or index that provides a value in a big blob of JSON.
https://github.com/cdown/json-key-from-value
Last synced: about 2 months ago
JSON representation
Find the key or index that provides a value in a big blob of JSON.
- Host: GitHub
- URL: https://github.com/cdown/json-key-from-value
- Owner: cdown
- License: mit
- Created: 2024-02-09T03:26:08.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-02-12T13:59:37.000Z (3 months ago)
- Last Synced: 2025-02-26T18:23:49.917Z (2 months ago)
- Language: Rust
- Size: 70.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# json-key-from-value | [](https://github.com/cdown/json-key-from-value/actions?query=branch%3Amaster)
If you often have big, unwieldy blobs of JSON which you have very deep trees
in, it can be a pain to go from a value that you know is the field you want to
retrieve to actually producing the correct selector.json-key-from-value will, given some JSON and a value to find, tell you how to
select it. If multiple keys or indexes are possible, they will all be printed.## Usage
For example, given the following JSON:
```
{"data":[{"foo":[
{"bar":[
{"id":1,"name":"yes"},
{"id":2,"name":"no"}
]},
{"baz":[
{"id":2,"name":null}
]}]
},{"qux":[
{"quux":
[[1,42],[2,2],[true, false]]
}]
}]}
```% json-key-from-value '"yes"' < json
["data"][0]["foo"][0]["bar"][0]["name"]% json-key-from-value 2 < json
["data"][0]["foo"][0]["bar"][1]["id"]
["data"][0]["foo"][1]["baz"][0]["id"]
["data"][1]["qux"][0]["quux"][1][0]
["data"][1]["qux"][0]["quux"][1][1]% json-key-from-value true < json
["data"][1]["qux"][0]["quux"][2][0]% json-key-from-value null < json
["data"][0]["foo"][1]["baz"][0]["name"]## Installation
cargo install json-key-from-value