invalid character '{' after top-level value
This message comes from encoding/json Unmarshal on Go go1.22.2. In this registry it is produced by 2 distinct mistakes. Positions in the real message vary with your input; the causes do not.
Causes
What produces this message
Extra data after a JSON document
Input
{"a": 1}{"b": 2}Exact message: invalid character '{' after top-level value
Fix: Split the documents, or if you meant a stream of records, use NDJSON and parse one line at a time.
NDJSON fed to a whole-document JSON parser
Input
{"a":1}
{"a":2}Exact message: invalid character '{' after top-level value
Fix: Read line by line and parse each line separately.
Same bug, other languages
What other parsers say about the same input
If a colleague reports a different message for what looks like the same file, this is why.
| Parser | Message for the same inputs |
|---|---|
| CPython json.loads | Extra data: line L column C (char N) |
| Gson | Use JsonReader.setLenient(true) to accept malformed JSON at line L column C path $… |
| Gson JsonParser (lenient off) | Use JsonReader.setLenient(true) to accept malformed JSON at line L column C path $… |
| JSON5 | JSON5: invalid character '{' at 1:9JSON5: invalid character '{' at 2:1 |
| JSON::PP | garbage after JSON object, at character offset N (before "…") |
| JavaScriptCore JSON.parse | JSON Parse error: Unable to parse JSON string |
| Newtonsoft.Json JsonConvert | Additional text encountered after finished reading JSON content: {. Path '', line L, position N. |
| Newtonsoft.Json JsonTextReader | Additional text encountered after finished reading JSON content: {. Path '', line L, position N. |
| Ruby JSON.parse | unexpected token at '…' |
| SpiderMonkey JSON.parse | JSON.parse: unexpected non-whitespace character after JSON data at line L column C of the JSON data |
| System.Text.Json Deserialize | '{' is invalid after a single JSON value. Expected end of data. Path: $ | LineNumber: L | BytePositionInLine: C. |
| System.Text.Json JsonDocument | '{' is invalid after a single JSON value. Expected end of data. LineNumber: L | BytePositionInLine: C. |
| V8 JSON.parse | Unexpected non-whitespace character after JSON at position N (line L column C) |
| hjson | Syntax error, found trailing characters at line L,1 >>>{"a":2} {"a":3} ...Syntax error, found trailing characters at line L,8 |
| json-bigint | Syntax error |
| json_decode | Syntax error |
| orjson | unexpected content after document: line L column C (char N) |
| serde_json::from_str | trailing characters at line L column C |
| ujson | Trailing data |
Sources
Standards this registry is checked against
- RFC 8259 (STD 90) — The JavaScript Object Notation (JSON) Data Interchange Format, T. Bray, Ed., 2017. The IETF Internet Standard for JSON. Obsoletes RFC 7159 and RFC 4627.
- ECMA-404, 2nd edition — The JSON Data Interchange Syntax, Ecma International, 2017. Ecma’s grammar for JSON. A normative reference of RFC 8259; the two define the same syntax.
- The Unicode Standard — The Unicode Standard, Core Specification, The Unicode Consortium, current. Normatively referenced by RFC 8259 for the definition of a character.
- IEEE 754-2019 — IEEE Standard for Floating-Point Arithmetic, IEEE, 2019. Referenced by RFC 8259 §6 as the basis for its interoperability guidance on numbers.
Only standards bodies and peer-reviewed venues are cited. Error strings on this site are observed by executing each parser; the standards above define what the parser is reacting to.