Files
el/lang/examples/json-array-traversal.el
2026-05-05 01:38:51 -05:00

22 lines
661 B
EmacsLisp

// json-array-traversal.el acceptance test for json_get dot-path with array
// indices.
//
// Before fix: json_get("...", "0.field") would substring-search for a literal
// key named `"0.field"` and find nothing, returning "".
//
// After fix: dot-path segments that are all digits are treated as array
// indices and the walker descends into the array.
fn test_array_traversal() -> String {
let s: String = "[{\"name\":\"alice\"},{\"name\":\"bob\"}]"
let a: String = json_get(s, "0.name")
let b: String = json_get(s, "1.name")
return a + "," + b
}
fn main() -> Int {
let r: String = test_array_traversal()
print(r)
return 0
}