{"record":{"id":"765a4016d37354ba","repo":"nikivdev/code","slug":"failed-to-decode-json-bytes-err","errorCode":null,"errorMessage":"failed to decode json bytes: {err}","messagePattern":"failed to decode json bytes: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/json_parse.rs","lineNumber":45,"sourceCode":"#[inline]\npub fn parse_json_bytes_in_place<T: DeserializeOwned>(bytes: &mut [u8]) -> Result<T> {\n    #[cfg(all(\n        feature = \"linux-host-simd-json\",\n        target_os = \"linux\",\n        any(target_arch = \"x86_64\", target_arch = \"aarch64\")\n    ))]\n    {\n        return simd_json::serde::from_slice(bytes)\n            .map_err(|err| anyhow!(\"failed to decode json bytes with simd-json: {err}\"));\n    }\n\n    #[cfg(not(all(\n        feature = \"linux-host-simd-json\",\n        target_os = \"linux\",\n        any(target_arch = \"x86_64\", target_arch = \"aarch64\")\n    )))]\n    {\n        serde_json::from_slice(bytes).map_err(|err| anyhow!(\"failed to decode json bytes: {err}\"))\n    }\n}\n","sourceCodeStart":27,"sourceCodeEnd":48,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/json_parse.rs#L27-L48","documentation":"parse_json_bytes_in_place's fallback path uses serde_json::from_slice when simd-json is unavailable for the target/features. Decode failures are wrapped as \"failed to decode json bytes: {err}\" with the serde_json error detail.","triggerScenarios":"Malformed or schema-incompatible JSON bytes passed to parse_json_bytes_in_place on non-simd builds (non-Linux, non-x86_64/aarch64, or feature disabled).","commonSituations":"Truncated file reads; extra whitespace/BOM at the start; producer schema changed (renamed fields, different types) while consumer struct is stale.","solutions":["Read the wrapped serde_json error for the exact position and cause","Verify the buffer holds one complete JSON value with no trailing garbage","Update the target struct to match the current producer schema","If input may have a BOM, strip it before parsing"],"exampleFix":"// before\nlet v: Event = parse_json_bytes_in_place(bytes)?;\n// after\nlet bytes = bytes.strip_prefix(b\"\\xef\\xbb\\xbf\").unwrap_or(bytes);\nlet v: Event = parse_json_bytes_in_place(bytes)?;","handlingStrategy":"try-catch","validationCode":"fn is_complete_json_bytes(bytes: &[u8]) -> bool {\n    serde_json::from_slice::<serde_json::Value>(bytes).is_ok()\n}","typeGuard":null,"tryCatchPattern":"match parse_json_bytes_in_place::<Event>(bytes) {\n    Ok(v) => handle(v),\n    Err(e) => {\n        eprintln!(\"bad json bytes: {e:#}\");\n        // quarantine bytes for inspection\n    }\n}","preventionTips":["Validate byte boundaries (single JSON value, no trailing data)","Strip BOM before parsing","Keep consumer structs aligned with producer schema","Add round-trip tests serde vs simd backends"],"tags":["json","serde","bytes","deserialization"],"backgroundTag":"json-decode-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}