Thanks to visit codestin.com
Credit goes to lib.rs

#json-path #json #extract #llm #pluck

json-pluck

Pluck a single value out of a serde_json::Value by dotted path or simple JSONPath. Lossy, forgiving, intended for LLM-emitted JSON.

1 unstable release

new 0.1.0 May 16, 2026

#2217 in Encoding

MIT/Apache

9KB
114 lines

json-pluck

Pluck a single value out of a serde_json::Value by dotted path or a tiny subset of JSONPath. Lossy and forgiving — built for the kind of LLM-emitted JSON where the answer is buried under unpredictable wrappers.

Supported path syntax:

  • a.b.c — nested object access
  • a.b[0] — array indexing
  • a.b[-1] — negative array indexing (-1 = last)
  • **.answer — first match anywhere under the root (BFS)

Example

use json_pluck::pluck;
use serde_json::json;

let v = json!({
    "result": {
        "items": [
            { "value": 1 },
            { "value": 42 }
        ]
    }
});
assert_eq!(pluck(&v, "result.items[1].value"), Some(&json!(42)));
assert_eq!(pluck(&v, "result.items[-1].value"), Some(&json!(42)));
assert_eq!(pluck(&v, "**.value"), Some(&json!(1)));

json-pluck

crates.io

Pluck a single value out of a serde_json::Value by dotted path or a tiny subset of JSONPath. Forgiving, built for LLM-emitted JSON where the answer is buried under unpredictable wrappers.

use json_pluck::pluck;
use serde_json::json;

let v = json!({ "result": { "items": [{ "value": 1 }, { "value": 42 }] } });
assert_eq!(pluck(&v, "result.items[1].value"), Some(&json!(42)));
assert_eq!(pluck(&v, "result.items[-1].value"), Some(&json!(42)));
assert_eq!(pluck(&v, "**.value"), Some(&json!(1)));

**.field BFS-searches the whole tree for the first match. MIT or Apache-2.0.

Dependencies

~265–740KB
~15K SLoC