{"record":{"id":"7f1516b8765d540c","repo":"ducaale/xh","slug":"expected-n-n","errorCode":null,"errorMessage":"expected {}\\n\\n{}","messagePattern":"expected (.+?)\\\\n\\\\n(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/nested_json.rs","lineNumber":238,"sourceCode":"/// with Value::null if needed\nfn arr_insert(arr: &mut Vec<Value>, index: usize, value: Value) {\n    while index >= arr.len() {\n        arr.push(Value::Null);\n    }\n    arr[index] = value;\n}\n\n/// Removes an element from array and replace it with `Value::Null`.\nfn remove_from_arr(arr: &mut [Value], index: usize) -> Option<Value> {\n    if index < arr.len() {\n        Some(mem::replace(&mut arr[index], Value::Null))\n    } else {\n        None\n    }\n}\n\nfn syntax_error(expected: &'static str, pos: usize, json_path: &str) -> anyhow::Error {\n    anyhow!(\n        \"expected {}\\n\\n{}\",\n        expected,\n        highlight_error(json_path, pos, pos + 1)\n    )\n}\n\nfn highlight_error(text: &str, start: usize, mut end: usize) -> String {\n    use unicode_width::UnicodeWidthStr;\n    // Apply right-padding so outside of the text could be highlighted\n    let text = format!(\"{text:<end$}\");\n    // Ensure end doesn't fall on non-char boundary\n    while !text.is_char_boundary(end) && end < text.len() {\n        end += 1;\n    }\n    format!(\n        \"  {}\\n  {}{}\",\n        text,\n        \" \".repeat(text[0..start].width()),","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/ducaale/xh/blob/2404aceecc08b0b2d100fedc96f57745cd5904dc/src/nested_json.rs#L220-L256","documentation":"`syntax_error` is the generic parser error for `--path-as-json`-style nested JSON path syntax. When `parse_path` encounters an unexpected character, it reports what was expected plus a `highlight_error` snippet pointing at the offending position in the user-supplied JSON path string.","triggerScenarios":"Calling xh with a malformed nested-JSON path expression (e.g. `xh :8080 users[0]==name[`). Any unbalanced bracket, bad operator, or stray character in the path reaches `parse_path` and produces `expected <thing>` plus the highlighted snippet.","commonSituations":"Hand-writing complex `key[subkey]==value` expressions in shell where brackets/quotes get mangled; typos like `foo]=bar` or `foo[bar==baz`; shell interpolation eating quotes or escaping characters.","solutions":["Read the highlighted snippet in the error to locate the offending character and fix the path syntax at that position.","Quote the whole argument in the shell to prevent bracket/quote mangling: `xh :8080 'users[0][name]==x'`.","Consult the nested-JSON syntax rules (brackets, indices, quoted keys) and simplify the expression step by step."],"exampleFix":"// before\nxh :8080 users[0==bob\n// after\nxh :8080 'users[0]==bob'","handlingStrategy":"validation","validationCode":"# pre-validate nested-JSON path args in scripts:\nEXPR='users[0][name]==bob'\necho \"$EXPR\" | grep -qE \"^[A-Za-z0-9_-]+(\\[[^]]+\\])*(==|:=|=)\" || { echo \"bad path expression: $EXPR\"; exit 1; }","typeGuard":null,"tryCatchPattern":"// parse the anyhow error and surface the highlighted snippet to the user:\nif let Err(e) = run() { eprintln!(\"{e:#}\"); std::process::exit(2); }","preventionTips":["Single-quote path expressions in the shell to protect brackets and quotes.","Build complex expressions incrementally, testing each nesting level.","Reuse validated expressions from scripts instead of retyping them."],"tags":["json","parser","syntax","cli"],"backgroundTag":"json-parse-error","analyzedSha":"2404aceecc08b0b2d100fedc96f57745cd5904dc","analyzedAt":"2026-09-13T19:13:33.814Z","contentChangedAt":"2026-09-13T19:13:33.814Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}