ENRU

Missing colon in JSON: “Expected … after property name”

Updated

Key. Colon. Value. In that order. Inside a JSON object every key is followed by : and then its value; anything else after a key, whether =, =>, a bare value or a comma, stops the parser right there.

The error and the fix

Three different habits, one error. Each line below fails at the character after the key:

{"port" = 8080}
{"port" => 8080}
{"port" 8080}

The JSON way to write it is always the same:

{"port": 8080}

The fourth habit is the sneaky one. {"red", "green"} looks like a list, but braces make an object, so "red" is read as a key and the comma after it as a missing colon. A list in JSON is an array: ["red", "green"].

Why JSON needs the colon

RFC 8259, section 4: “A single colon comes after each name, separating the name from the value”, or in grammar form member = string name-separator value, where the name separator is :. There is no shorthand: no key without a value, no other separator, no implicit value of true.

Missing colon error messages by parser

The value right after the key, {"a" 1}, and an equals sign in place of the colon, {"a" = 1}:

Parser{"a" 1}{"a" = 1}
Chrome, Edge, Node.js (V8)Expected ':' after property name in JSON at position 5 (line 1 column 6)Expected ':' after property name in JSON at position 5 (line 1 column 6)
Node.js 18, older Chrome (V8 10.2)Unexpected number in JSON at position 5Unexpected token = in JSON at position 5
FirefoxJSON.parse: expected ':' after property name in object at line 1 column 6 of the JSON dataJSON.parse: expected ':' after property name in object at line 1 column 6 of the JSON data
SafariJSON Parse error: Expected ':' before value in object property definitionJSON Parse error: Expected ':' before value in object property definition
PythonExpecting ':' delimiter: line 1 column 6 (char 5)Expecting ':' delimiter: line 1 column 6 (char 5)
Go (encoding/json)invalid character '1' after object keyinvalid character '=' after object key
Java (Jackson 2)Unexpected character ('1' (code 49)): was expecting a colon to separate field name and valueUnexpected character ('=' (code 61)): was expecting a colon to separate field name and value
C# (System.Text.Json)'1' is invalid after a property name. Expected a ':'.'=' is invalid after a property name. Expected a ':'.
C# (Newtonsoft.Json)Invalid character after parsing property name. Expected ':' but got: 1. Path '', line 1, position 5.Invalid character after parsing property name. Expected ':' but got: =. Path '', line 1, position 5.
PHP (json_decode)Syntax error, json_last_error() 4Syntax error, json_last_error() 4
Rust (serde_json)expected : at line 1 column 6expected : at line 1 column 6
jqjq: parse error: Expected separator between values at line 1, column 7jq: parse error: Invalid numeric literal at line 1, column 7
RapidJSONMissing a colon after a name of object member.Missing a colon after a name of object member.

This is one of the few errors that almost every parser names correctly. The exceptions are old V8, which describes the token it didn’t expect, and jq, whose “separator” means a colon here. For the set-like {"red", "green"}, Chrome and Python give the same missing-colon messages, pointing at the comma. Checked by running: Node.js 18, 24 and 25.1, Safari 27, Python 3.9 and 3.14, Go 1.25–1.27, Jackson 2.22 (Jackson 3 says “property name”), System.Text.Json and Newtonsoft.Json 13.0.4, PHP 8.3 and 8.5, serde_json 1.0, jq 1.7 and 1.8. Firefox and RapidJSON: from their source code; Firefox’s messages are also listed on Mozilla’s reference pages.

Where a missing colon comes from

  • = from other formats: .ini and .env files, shell variables, URL query strings.
  • => from code: PHP arrays and Ruby hashes printed with inspect look almost like JSON.
  • A set or a list in braces: Python sets, C# collection initializers and many configuration languages use {a, b} for a list.
  • A key with its value missing, for example after a find-and-replace removed : null or a template printed an empty value. A key directly followed by } gets reported the same way.

How to produce the colon in code

The usual cause in code is text from another format being passed off as JSON. Parse it with the tools for that format, build a map, and let the serializer write the colons; for collections, make sure a set becomes an array.

JavaScript

// key=value lines: build an object, then let JSON.stringify write the colons.
const lines = "debug=true\nport=8080".split("\n");
console.log(JSON.stringify(Object.fromEntries(lines.map((l) => l.split("="))))); // {"debug":"true","port":"8080"}

// A Set has no keys of its own: JSON.stringify writes {} for it.
const colors = new Set(["red", "green"]);
console.log(JSON.stringify(colors), JSON.stringify(Array.from(colors))); // {} ["red","green"]

Python

import json

colors = {"red", "green"}  # a set: braces, but no keys
try:
    json.dumps(colors)
except TypeError as e:
    print(e)  # Object of type set is not JSON serializable
print(json.dumps(sorted(colors)))  # ["green", "red"]

Go

package main

import (
	"encoding/json"
	"fmt"
	"strings"
)

func main() {
	pairs := map[string]string{}
	for _, line := range strings.Split("debug=true\nport=8080", "\n") {
		k, v, _ := strings.Cut(line, "=")
		pairs[k] = v
	}
	b, _ := json.Marshal(pairs)
	fmt.Println(string(b)) // {"debug":"true","port":"8080"}
}

Java (Jackson)

import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

Set<String> colors = new TreeSet<>(List.of("red", "green"));
System.out.println(new ObjectMapper().writeValueAsString(colors)); // ["green","red"]

C#

using System.Text.Json;

var colors = new SortedSet<string> { "red", "green" };
Console.WriteLine(JsonSerializer.Serialize(colors)); // ["green","red"]

PHP

$config = ['debug' => true, 'port' => 8080]; // PHP writes key => value
echo json_encode($config);                    // {"debug":true,"port":8080}

How to keep colons where they belong

  • Don’t convert formats by search and replace: = to : breaks on the first value that contains =.
  • When a value is unknown, write null, not nothing.
  • Use [ ] for lists, { } only for key-value pairs.
  • Run hand-edited files through the JSON validator before committing them.

Try it in the validator

Open a sample with a missing colon in the JSON validator. It reports missing_colon at the character that stands where : should be and shows what it found there.

Related: missing comma, unquoted key, trailing comma, and all JSON errors.

Missing colon FAQ

Can I use = instead of : in JSON?

No. The colon is the only separator between a key and its value. = belongs to .ini and .env files and to query strings.

Can a JSON key have no value?

No. Every key needs a value; write null if there isn’t one. A key on its own is reported as a missing colon.

Why is {"red", "green"} a missing colon and not a list?

Braces always open an object in JSON, and an object holds key-value pairs. The parser reads "red" as a key and expects a colon after it. Lists use square brackets.