Python RSON
RSON is a superset of the JSON format. It extends JSON with the primary goal of allowing references in the JSON itself.
In addition to that, RSON also allows:
- Line comments
- Block comments
- Trailing commas
These are just some nicities are not the primary goal of the RSON format.
Usage
The RSON format allows references by adding 2 types of tokens:
- DEF node - defines a
ref-namefor the value - REF node - references the given
ref-name
The DEF node can be used on any JSON value. This node defines a name for the value which can then used
to refer to the same value.
The REF node can only appear as an object value or an array member, and is used to refer to a
defined name.
Here is an example of how this would work:
// team.rson
[
{
"members": [
{
"name": "Alice",
"role": $ROLE_DEVELOPER
},
{
"name": "Bob",
"role": $ROLE_MANAGER
},
{
"name": "Charlie",
"role": $ROLE_DESIGNER
}
],
"roles": [
{
"name": "Developer"
}(ROLE_DEVELOPER),
{
"name": "Designer"
}(ROLE_DESIGNER),
{
"name": "Manager"
}(ROLE_MANAGER)
]
}
]
We can load the teams.rson file with the following code:
from rson import load
with open("teams.rson") as f:
team = load(f)[0]
target_role_name = input("Which role to look for? ")
for role in team["roles"]:
if role["name"].lower() == target_role_name.lower():
target_role = role
break
else:
print("Could not find role " + target_role_name)
exit()
members_with_role = [
member for member in team["members"]
if member["role"] is target_role # <- note the identity check here
]
print(f"Found {len(members_with_role)} members with role {role['name']}:")
for i, member in enumerate(members_with_role):
print(f"\t{i}. {member['name']}")
and a sample execution:
Which role to look for? developer
Found 2 members with role Developer:
0. Alice
1. David
Specification
The ref-name must conform to the following regex:
[A-Za-z_][A-Za-z_0-9]*
Or, in plain english:
The first character must be a valid english letter or an underscore, and the following letters must be either an english letter, an underscore or a digit. A
ref-namemust have at least 1 character (the first character).
A DEF node can be used for every JSON value, so this makes the following
valid as well:
{
"organization": {
"name": "Xpo Development"(ORG_NAME)
},
"title": $ORG_NAME
}
Contributing
Feel free to open an issue or a PR.
ToDo
- Implement the
loadfunction - Implement the
loadsfunction - Implement the
dumpfunction - Implement the
dumpsfunction
Metadata
Release files for python-rson 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python_rson-0.1.1.tar.gz | 6.1 kB | Without provenance | Details for python_rson-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_rson-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for python_rson-0.1.1-py3-none-any.whl |
Total release size: 12.8 kB
Release files / python_rson-0.1.1.tar.gz
| Download URL | python_rson-0.1.1.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e9ff99a881d5f9487f9c680be927924c1e60083e8947bd741ed7e275ab7f4944
|
|
BLAKE2b-256 checksum How to use checksums |
2de38f976a94203aa34c7236cc5f02f35ff93445f4bac60a965515b8f6aa9c94
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.21
|
Release files / python_rson-0.1.1-py3-none-any.whl
| Download URL | python_rson-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
017cbcea2d424cc23463089840cc86edb92473b42ba5a30c9f5ede1df1c65037
|
|
BLAKE2b-256 checksum How to use checksums |
f55f9e3e3ea43e3aed2ba2f68aa92a46d0ed85dc84c5152a72a5ecba236017ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.21
|
Security for python-rson 0.1.1
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.