A package to parse out C/JS style block and single line comments from JSON files
Project description
jsonjsc
A Python library for parsing out C/Javascript style comments in JSON files.
Install
pip install jsonjsc
Features
- Simple and easy to use library with no other dependencies.
- Supports C/JS block (
/* */
) and single line (//
) comments. - Retains the line number and character column of JSON content after parsing, letting syntax error positions get properly reported by the normal Python JSON decoder.
- Is easily dropped into existing JSON library usage as a decoder class.
- Test backed via
unittest
.
Example
import json
import jsonjsc
TEST_JSON_DECODER = r'''{
/*
This is a test of the JSON decoder in full
*/
"test1": "message1", // this comment should parse out.
// "junk1": "message",
/*
"junk2": "another message",
*/
"test2": "message2"
}'''
test = json.loads(TEST_JSON_DECODER, cls=jsonjsc.JSONCommentDecoder)
print(test["test1"])
if "junk1" not in test:
print("I guess junk1 was commented out?")
if "junk2" not in test:
print("I guess junk2 was commented out too!")
print(test["test2"])
TODOs
Implementation could probably be sped up significantly as it uses character by character searches to test if comments are in string values or not. No performance metrics have been taken.
License
Licensed under the MIT License. See LICENSE for more information.
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
jsonjsc-1.1.2.tar.gz
(3.6 kB
view hashes)
Built Distribution
Close
Hashes for jsonjsc-1.1.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6a232848c7b305749229e40dec2ba7ea711ebd4565bcdacbadfa46b04e12b1b |
|
MD5 | 546d2355b44ad4085658eedfcd789468 |
|
BLAKE2b-256 | 361add3a0bf204903c34a68feac0550931b89ad85eb33804aff87a18aa007b6c |