Anuken/Mindustry · error · SerializationException
Content JSON must be an object, not a single value.
Error message
Content JSON must be an object, not a single value.
What it means
In parse(), the raw JSON is parsed and the result must be an arc JsonValue (i.e. a JSON object at top level). If the file is a bare scalar or array at the root, fromJson yields a non-JsonValue and the parser rejects it, because every content type parser expects an object to map onto fields.
Source
Thrown at core/src/mindustry/mod/ContentParser.java:1035
* @param name the name of the file without its extension
* @param json the json to parse
* @param type the type of content this is
* @param file file that this content is being parsed from
* @return the content that was parsed
*/
public Content parse(LoadedMod mod, String name, String json, Fi file, ContentType type) throws Exception{
checkInit();
//remove extra # characters to make it valid json... apparently some people have *unquoted* # characters in their json
if(file.extension().equals("json")){
json = json.replace("#", "\\#");
}
currentFile = file;
currentMod = mod;
var rawValue = parser.fromJson(null, Jval.read(json).toString(Jformat.plain));
if(!(rawValue instanceof JsonValue value)) throw new SerializationException("Content JSON must be an object, not a single value.");
if(!parsers.containsKey(type)){
throw new SerializationException("No parsers for content type '" + type + "'");
}
boolean located = allowPatching && locate(type, name) != null;
Content c = parsers.get(type).parse(mod.name, name, value);
c.minfo.sourceFile = file;
toBeParsed.add(c);
if(!located){
c.minfo.mod = mod;
}
currentMod = null;
currentFile = null;
return c;
}View on GitHub (pinned to f695ad7e60)
Solutions
- Make the file's top-level JSON an object enclosed in { }.
- Each content file should define exactly one content entry as an object.
Example fix
// before
[ { "name":"a" }, { "name":"b" } ]
// after
{ "name": "a" } // one file per entry Defensive patterns
Strategy: validation
Validate before calling
Object raw = parser.fromJson(null, Jval.read(json).toString(Jformat.plain));
if(!(raw instanceof JsonValue)) throw new IllegalStateException("Content file root must be a JSON object"); Type guard
boolean isJsonObject(Object raw){ return raw instanceof JsonValue && ((JsonValue)raw).isObject(); } Prevention
- Start every content file with { and end with }.
- One content entry per file.
When it happens
Trigger: A content file whose root JSON node is a number, string, boolean, or array rather than an object.
Common situations: Authoring a content file as a single quoted string or array; a malformed/truncated file; accidentally saving a list of items instead of one item definition.
Related errors
- Unknown consumption type: '${child.name}' for block '${block
- Blocks cannot be larger than ${maxBlockSize}
- Unit '${name}' has an incorrect type. Types must be strings.
- Missing a valid 'block' in 'requirements'
- SectorPresets must have a sector number.
AI-assisted analysis of Anuken/Mindustry@f695ad7e60 (2026-08-14).
Data as JSON: /api/errors/058229795b0e21a5.
Report an issue: GitHub.