Skip to main content

jsonc_sdict 即典

maybe is the only solution support round-trip(keep comments both for read&write) for jsonc/hjson, with easy api design.

bundled sdict = deepmerge + deepdiff + benedict

bundled weakList & OrderedWeakList because cpython has not implemented.

[!WARNING] some code was written by AI, and I'm re-writing/cleanup code in the future.

Usage

jc = jsonc(my_dict)
# or jsonc(json.loads(my_str), my_str)
# jc.update(hjson.loads(jc.body)) # if my_str
jc["//unique-keyname"] = "my comment but at end of body"
jc.insert_comment({
    "/*\\nunique-keyname-1": "my multi-\\nline comments\\n"
    "//\\nunique-keyname-2": "my line-above comments"
    "//your data key overlap with comment-keyname rule?" + DATA: ["treat as data, not comment"] # rare edge case
    }, "existedKey"
)
jc.body = hjson.dumps(jc)
f.write(jc.body)

comment keyname rule

TODO: english version

{
    '//0<SEED>': ' "": null, # dict内的顺序与真实的注释出现位置一致
    '0': 0,
    '//1<SEED>': ' 0', # 行内注释,在dict内的排序需要在真实数据的后面。
    '//2<SEED>': ' "1": 1,/* 1 */\n', # 行上注释,则末尾应该有个\n
    '/*,3<SEED>': ' 2 ', # 不应为`/*`,而应为`/*,`,其中prefix[0:1]=="/*",而prefix[2]==","代表这个多行注释应该`放到一个逗号前面`的意思; 多行注释按`向下查找的栈`规则,所以需要放到真实数据 "2": 2的前面。
    '2': 2,
    '/*\n4<SEED>': ' 👻 ', # `/*\n`代表多行注释的末尾是一个换行符,也相当于多行版本的行上注释
    '/*,5<SEED>': ' 3\n  4\n  * 5\n  ', # 不应为`/*`,而应为`/*,`
    '3': 3,
    '/*v6<SEED>': ' 6 ', # `/*v` 代表多行注释应该出现在实际的value槽位之前
    '6//': 6,
    '/*k7<SEED>': ' 7 ', # `/*k` 代表多行注释应该出现在实际的key槽位之前
    '7': 7,
    '/*\n8<SEED>': ' 8 ', # `/*\n`代表多行注释应该在**下方**kv数据的末尾,然后是换行符(这一点不要与 "//...": "...\n"行上注释末尾必须是\n 的规则混淆了)
    '8': 8,
    '//9<SEED>': ' "9": 9',
    '/-node<SEED>': jsonc({'just ignore these': 'i am in node comment'}),
    'node': jsonc({'do not ignore me': 'i am real data!'}),
}

同理,/*:代表多行注释应该出现在冒号前面,key槽位的后面。

json loads() substitute

pypi commits issues about lack
spyoungtech/json-five ⭐ 🕒 LAST🕒 🎯 🎯close Python JSON5 parser with round-trip preservation of comments can keep comment, but in AST-tree style with lots of re-defined concepts (e.g: BlockComment/wsc_before)
tusharsadhwani/json5kit ⭐ 🕒 LAST🕒 🎯 🎯close A Roundtrip parser and CST for JSON, JSONC and JSON5.
dpranke/pyjson5 ⭐ 🕒 LAST🕒 🎯 🎯close A Python implementation of the JSON5 data format
austinyu/ujson5 ⭐ 🕒 LAST🕒 🎯 🎯close A fast JSON5 encoder/decoder for Python
qvecs/qjson5 ⭐ 🕒 LAST🕒 🎯 🎯close 📎 A quick JSON5 implementation written in C, with Python bindings.

other format that support round-trip

Metadata

Release files for jsonc-sdict 0.1.20260302

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

Source distribution (sdist)

Source distribution for jsonc-sdict 0.1.20260302
File Size Uploaded
jsonc_sdict-0.1.20260302.tar.gz 38.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jsonc-sdict 0.1.20260302
File Interpreter ABI Platform
jsonc_sdict-0.1.20260302-py3-none-any.whl Python 3 none any Details

Total release size: 68.9 kB

Release files / jsonc_sdict-0.1.20260302.tar.gz

Download URL jsonc_sdict-0.1.20260302.tar.gz
Size 38.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6e6de4d898ebe81976a33852f43cb6e6f6fb727153415aa36c541f21d0b49bd1
BLAKE2b-256 checksum
How to use checksums
d7a59d5cdb1a710193f94809a25559521baecb9c9f6b988d064cf20d48036168
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 2, 2026.

Transparency log

Release files / jsonc_sdict-0.1.20260302-py3-none-any.whl

Download URL jsonc_sdict-0.1.20260302-py3-none-any.whl
Size 30.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b31ed6b98e2b9045afaa749d91d86c5445a1d5df66b12cdacfc63556b754a983
BLAKE2b-256 checksum
How to use checksums
254ef72b93e5df1023659f27823175e7d8f2e7a7eca15e80f3708875fbe0c83e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 2, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.20260302 This release

2 release files

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