Skip to main content

ARSON: A Restructured Object Notation

ARSON is JSON, with a little bit of sugar: Comments, Commas, and Tags.

For example:

{
    "numbers": +0123.0,       # Can have leading zeros
    "octal": 0o10,            # Oh, and comments too
    "hex": 0xFF,              #
    "binary": 0b1000_0001,    # Number literals can have _'s 

    "lists": [1,2,3,],        # Lists can have trailing commas

    "strings": "At least \x61 \u0061 and \U00000061 work now",
    "or": 'a string',         # both "" and '' work.

    "records": {
        "a": 1,               # Must have unique keys
        "b": 2,               # and the order must be kept
    },
}

Along with some sugar atop JSON, ARSON supports tagging literals to represent types outside of JSON:

  • @datetime "2017-11-22T23:32:07.100497Z", a tagged RFC 3339 datestamp
  • @duration 60 (a duration in seconds, float or int)
  • @base64 "...==", a base64 encoded bytestring
  • @set, @dict, @complex, @bytestring

Quickstart

Use pip install arson to get the latest copy of the python library. The arson library has two methods, parse and dump.

import arson

print(arson.parse(arson.dump([1,2,3])))

If you want to use your own tagged object types, you can create a custom Codec:

import arson

class Example:
    def __init__(self, value):
        self.value = value
    def __repr__(self):
        return f"Example {self.value}"

def object_to_tagged(obj):
    if isinstance(obj, Example):
        return "Example", {"value": obj.value}
    else:
        raise NotImplementedError()

def tagged_to_object(name, value):
    if name == "Example":
        return Example(value['value'])
    else:
        raise NotImplementedError()
        
codec = arson.Codec(object_to_tagged, tagged_to_object)

print(codec.parse(codec.dump(Example(1))))

Supported Datatypes

This library supports serializing and deserializing the following types

  • str, int, bool
  • float (including Infinity and Nan)
  • list, tuple (but will always return a list)
  • dict, set, OrderedDict (but will use dicts on 3.7+)
  • datetime, timedelta (but will convert times to UTC)
  • bytestring, bytearray (but will return a bytearray)
  • complex

The fixed width numeric types are currently unsupported (Sorry).

ARSON in a Nutshell

  • File MUST be utf-8, not cesu-8/utf-16/utf-32, without surrogate pairs.
  • Use #.... <end of line> for comments
  • Byte Order Mark is treated as whitespace (along with \x09, \x0a, \x0d, \x20)
  • ARSON Document is any ARSON Object, (i.e 1 is a valid ARSON file).
  • Lists are [], [obj], [obj,], [obj, obj] ... (trailing comma optional)
  • Records are {"key": value}, keys must be unique, order must be preserved.
  • Built-ins: true, false, null
  • "unicode strings" with escapes \" \\ \/ \b \f \n \r \t \uFFFF \UFFFFFFFF, no control codes unecaped, and '' can be used instead of "".
  • int/float numbers (unary plus or minus, allowleading zeros, hex, octal, and binary integer liters)
  • Tagged literals: @name [1,2,3] for any other type of value.

Errors are fatal. A record with duplicate keys, or a string too long, or a number too big to represent MUST cause the parse to fail outright.

Metadata

Release files for arson 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for arson 0.0.7
File Size Uploaded Provenance
arson-0.0.7.tar.gz 10.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for arson 0.0.7
File Interpreter ABI Platform
arson-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 20.0 kB

Release files / arson-0.0.7.tar.gz

Download URL arson-0.0.7.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
944cf4600047b5cd3d7d630aa3aba59842af7deec519f7aaf4bd55ad4f098607
BLAKE2b-256 checksum
How to use checksums
821a8338adf4f6a675c3f1dace82c39e830fa14568c6cab45e82c8f87e4d5df2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.10

Release files / arson-0.0.7-py3-none-any.whl

Download URL arson-0.0.7-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f0f2250c654c08a08a4ff452208294108075f4e081f596134b5edb8ca2dfb830
BLAKE2b-256 checksum
How to use checksums
5eee1e73e741f5d7e90e83d8e52419157f1d0eb052713a1064b58b2c72be67b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.10

Security for arson 0.0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page