Formatter Validator Minifier Escape / Unescape JSON ↔ String JSON ↔ YAML JSON → CSV NDJSON / JSON Lines JSON → Types JSON ↔ XML JSON Diff JSON Patch Canonicalize (RFC 8785) Schema Validator Schema Generator JSONPath Tester JWT Decoder JSON Errors Schemas More Tools
JSONTools / JSON errors / Bare minus sign where a number was expected
JSON error registry · Number format

Bare minus sign where a number was expected

A minus with no digits after it. Typically a templated value that resolved to empty, leaving the sign behind.

The input

Fails to parse
{"a": -}
Parses correctly
{"a": -1}

Open this broken input in the formatter →

How to fix it

Emit `null` or `0` when the value is missing, and check your template for an unsubstituted placeholder.

Seeing `-` alone is a strong sign of string-concatenation serialisation rather than a real JSON writer.

What each parser reports

Every message below was captured by running this exact input through the parser named. 18 of 21 parsers rejected it; 3 accepted it.

Parser Exact message
CPython json.loads
CPython 3.12.3
Expecting value: line 1 column 7 (char 6)
what this message means →
encoding/json Unmarshal
Go go1.22.2
invalid character '}' in numeric literal
what this message means →
Gson
Java 21.0.12
accepted — no error
Gson JsonParser (lenient off)
Java 21.0.12
accepted — no error
hjson
Node.js 22.22.2
End of input while parsing an object (missing '}') at line 1,8 >>>"a": -} ...
what this message means →
Jackson ObjectMapper
Java 21.0.12
Unexpected character ('}' (code 125)) in numeric value: expected digit (0-9) to follow minus sign, for valid numeric value
what this message means →
JavaScriptCore JSON.parse
JavaScriptCore (Bun 1.4.1)
JSON Parse error: Invalid number
what this message means →
json-bigint
Node.js 22.22.2
Bad number
JSON5
Node.js 22.22.2
JSON5: invalid character '}' at 1:8
what this message means →
JSON::PP
Perl 5.038002
malformed number (no digits after initial minus), at character offset 8 (before "(end of string)")
what this message means →
json_decode
PHP 8.3.6
Syntax error
Newtonsoft.Json JsonConvert
Newtonsoft.Json 13.0.3 on .NET 8.0.30
Input string '-' is not a valid number. Path 'a', line 1, position 7.
what this message means →
Newtonsoft.Json JsonTextReader
Newtonsoft.Json 13.0.3 on .NET 8.0.30
Input string '-' is not a valid number. Path 'a', line 1, position 7.
what this message means →
orjson
CPython 3.12.3
no digit after sign: line 1 column 8 (char 7)
what this message means →
Ruby JSON.parse
Ruby 3.2.3
unexpected token at '{"a": -}'
serde_json::from_str
Rust (serde_json 1.x)
invalid number at line 1 column 8
what this message means →
SpiderMonkey JSON.parse
SpiderMonkey 115
JSON.parse: unexpected non-digit at line 1 column 8 of the JSON data
what this message means →
System.Text.Json Deserialize
.NET 8.0.30
'}' is invalid within a number, immediately after a sign character ('+' or '-'). Expected a digit ('0'-'9'). Path: $ | LineNumber: 0 | BytePositionInLine: 7.
what this message means →
System.Text.Json JsonDocument
.NET 8.0.30
'}' is invalid within a number, immediately after a sign character ('+' or '-'). Expected a digit ('0'-'9'). LineNumber: 0 | BytePositionInLine: 7.
what this message means →
ujson
CPython 3.12.3
accepted — no error
V8 JSON.parse
Node.js 22.22.2
No number after minus sign in JSON at position 7 (line 1 column 8)
what this message means →

What the specification says

The exact sections that govern this error. Descriptions are our paraphrase; follow the links for the normative text.

Body Section
IETF
A number is base 10, optionally signed with a minus, with an optional fraction and exponent. The section states that leading zeros are not allowed, and that values which cannot be represented in its grammar — Infinity and NaN among them — are not permitted.
Ecma International
A number is decimal digits with no superfluous leading zero. Values such as Infinity and NaN are not permitted.

Other errors in this category

Leading zero in a JSON number

JSON's number grammar forbids a leading zero on a multi-digit integer, to avoid any suggestion of octal. Zip codes, phone numbers …

Leading plus sign in a JSON number

JSON allows a leading minus but not a leading plus. Explicitly signed values from spreadsheets or telemetry formats trip this.…

Trailing decimal point in a JSON number

`1.` is valid in C and JavaScript but not in JSON, which requires at least one digit after the decimal point.…

Leading decimal point in a JSON number

`.5` is valid in several languages but JSON requires a digit before the decimal point.…

Hexadecimal number in JSON

JSON numbers are decimal only. `0x1F` comes from a language literal or from a value that should have stayed a string, such as a co…

← All JSON parser errors