Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
This is an alternative JSON decoder/encoder that supports some extra
features. It takes a lot of inspiration from the json
module in the
standard library and exposes the same high level API: load
, loads
,
dump
, dumps
, JSONDecoder
, and JSONEncoder
.
In many cases, jsun
can be swapped in by installing the package then
simply updating imports to use jsun
instead of json
.
Trailing commas
Line comments starting with //
All valid Python ints and floats:
Math constants:
Literal (unquoted) dates and times:
Decoding an empty string will produce None
rather than an exception
(an exception will be raised if extras are disabled)
All parsing methods can be overridden if some additional customization is required. In particular, the object and array parsers can be overridden
A pre-parse method can be provided to handle values before the regular JSON parsers are applied
A fallback parsing method can be provided to handle additional types of values if none of the default parsers are suitable
When errors are encountered, specific exceptions are raised (all
derived from the built-in ValueError
)
The jsun
encoder is very similar to the standard library encoder (and
is in fact a subclass of json.JSONEncoder
). Currently, it supports
only a couple of extra features:
NOTE: There is some asymmetry here. E.g., date and datetime objects should be converted to literals instead of quoted strings.
All the extra features can be turned off with a flag:
>>> from jsun import decode
>>> decode("[1, 2, 3,]")
[1, 2, 3]
>>> decode("[1, 2, 3,]", enable_extras=False)
<exception traceback>
An empty string input is converted to None
rather than raising an
exception (only if extras are enabled).
When decoding, instead of object_hook
and object_hook_pairs
,
there's just a single object_converter
argument. It's essentially
the same as object_hook
. object_hook_pairs
seems unnecessary
nowadays since dict
s are ordered.
The default object type is jsun.obj.JSONObject
instead of dict
. A
JSONObject
is a bucket of properties that can be accessed via dotted
or bracket notation. Pass object_converter=None
to get back
dict
s instead.
A bonus feature is that configuration can be loaded from INI files where the keys are split on dots to create sub-objects and the values are encoded as JSON.
This is quite similar to TOML and some of the features of jsun
, like
literal dates, are inspired by TOML.
This feature was originally developed in 2014 as part of the
django-local-settings
project, about a year and half after TOML was
first released but before I'd heard of it.
{}
syntax (AKA "inline tables" in TOML) can
span multiple linesMy first choice was jsonish
but that's already taken. My second choice
was jsonesque
but it's also taken, and it's hard to type. jsun
is
nice because it's easy to type and easy to swap in for json
by just
changing a single letter.
There's a suite of unit tests, which also tests against the JSON checker files at https://json.org/JSON_checker/. Coverage is currently at 82%.
FAQs
JSON encoding & decoding with extra features
We found that jsun demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.