Mojangson is a JavaScript library for parsing, simplifying, stringifying, and normalizing Mojangson (Minecraft's data tag format). It provides functionality to convert Mojangson strings into JavaScript objects, and vice-versa, handling its unique deviations from standard JSON. Key differences include support for indexed arrays, trailing commas in arrays and objects, unquoted strings (for keys and values), and numbers with type suffixes (e.g., `5b`, `100l`). The current stable version is 2.0.4. Releases are infrequent, focusing on bug fixes and grammar improvements. This library differentiates itself by accurately implementing the specific Mojangson grammar, making it essential for applications interacting with Minecraft's NBT data tags or command syntax, where standard JSON parsers would fail due to the non-standard syntax.
npm install mojangsonVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing, simplifying, stringifying, and normalizing Mojangson strings, highlighting the library's core functionalities.
Update consuming code to expect the new structured output (e.g., `data.value.mykey.value` instead of `data.mykey`). If a simplified representation is needed, use `mojangson.simplify(parsedData)`.
Use `mojangson.parse` for initial parsing and work with the structured output if type fidelity is required for stringification. Only use `simplify` when a plain JavaScript object is sufficient and type information is not critical.
Construct your input objects with explicit `type` properties (e.g., `{ type: 'string', value: 'hello' }` or `{ type: 'compound', value: { key: { type: 'int', value: 123 } } }`) to match the expected format for `stringify`.Always use `mojangson.parse` when dealing with Mojangson strings. Do not attempt to use `JSON.parse()` as it is incompatible.
Review the Mojangson string for compliance with the Mojangson specification. Check for correct curly braces, square brackets, colons, commas, and ensure values are properly formatted. Refer to the Mojangson specification (e.g., Minecraft Wiki Data tags) for correct syntax.
Ensure the input to `mojangson.simplify` is the direct output of `mojangson.parse`. This error was specifically addressed in version 2.0.3, so upgrading to 2.0.3 or higher should resolve issues related to simplifying arrays.
Upgrade the `mojangson` package to version 2.0.2 or newer to ensure correct parsing of strings that may begin with numeric characters.
No dependency data recorded yet.