Skip to main content

Python Mojangson parser

Project description

mojangson

Python PyPI

A small Python library for parsing, stringifying, simplifying, and normalizing Mojangson - mojang's variant of json.

Installation

pip install mojangson

API

parse - Parse Mojangson text into a typed dict representation.

stringify - Convert a typed Mojangson dict back to a Mojangson string.

simplify - Simplify a typed Mojangson dict into a regular Python dict/list/primitive values, stripping Minecraft-specific type suffixes.

normalize - Normalize Mojangson text by parsing and then stringifying it - ensures consistent formatting and ordering.

Usage

from mojangson import parse, stringify, simplify, normalize

mojangson_string = '{key:value}'

mojangson_parsed = parse(mojangson_string)
print(mojangson_parsed)
# {'type': 'compound', 'value': {'key': {'type': 'string', 'value': 'value'}}}

print(simplify(mojangson_parsed))
# {'key': 'value'}

mojangson_stringified = stringify(mojangson_parsed)
print(mojangson_stringified)
# {key:value}

print(normalize(mojangson_string) == mojangson_stringified)
# True

CLI

Syntax:

mojangson <command> [input] [-f FILE] [-o FILE]

Arguments:

Argument Description
input Mojangson string, if not using -f/--file
-f, --file Path to an input file containing a Mojangson string
-o, --output Path to an output file. If not provided, output is printed to stdout

Examples:

mojangson parse "{a:b}"
# {'type': 'compound', 'value': {'a': {'type': 'string', 'value': 'b'}}}

mojangson simplify "{'type': 'compound', 'value': {'a': {'type': 'string', 'value': 'b'}}}" -o output.txt
# writes {'a': 'b'} to output.txt

mojangson stringify -f input.json
# reads from input.json

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mojangson-0.2.1.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mojangson-0.2.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file mojangson-0.2.1.tar.gz.

File metadata

  • Download URL: mojangson-0.2.1.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for mojangson-0.2.1.tar.gz
Algorithm Hash digest
SHA256 67919f4710b05bb1043e72b92b9f9397a20d6bda0556326c0e8478d7ca40e8bd
MD5 9dd9bee253ae37d305549105551f7097
BLAKE2b-256 1b421006e0ac4e36c03621a5b9b1d5ccd8b5cd038f49f41d366ac4b39e6a5172

See more details on using hashes here.

File details

Details for the file mojangson-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: mojangson-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for mojangson-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ece2b14590b79de24d91b58dcf2d74069cf7d661da64fe03aa84bd9bac8f3a7a
MD5 75a1660d9000e9d52fa9f98a2dd1b240
BLAKE2b-256 00e338bc1f9c65a1bd8c07e512c3a8d3d48ba633ff24b2e128cdcde5a9fcc761

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page