Crates.io | json-key-from-value |
lib.rs | json-key-from-value |
version | 0.1.0 |
source | src |
created_at | 2024-02-09 03:34:49.521336 |
updated_at | 2024-02-09 03:34:49.521336 |
description | Find the key or index that provides a value in a big blob of JSON. |
homepage | |
repository | https://github.com/cdown/json-key-from-value |
max_upload_size | |
id | 1133277 |
size | 14,252 |
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.
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"]
cargo install json-key-from-value