This is a JSON parsing module that can get along with comments in JSON files.
Project description
Introduction
This python module allows reading JSON files including comments.
This module is an improved version of Vaidik Kapoor’s commentjson module provided at PyPi at https://pypi.python.org/pypi/commentjson/. The original version has been ported to Python 3 and the regular expressions have been improved.
Information about this module can be found here:
Foreword
The original commentjson module implemented by Vaidik Kapoor makes use of regular expressions to preprocess files before forwarding the data to the Python json parser to actually parse the data. Of course this approach must be considered to be a hack, especially as the existing implementation does not manage all special situations in parsing.
The library jk_commentjson improves on the current implementation by fixing and extending the expression approach. Though the current approach works quite well nevertheless it is still a hack.
The author of jk_commentjson will replace the existing implementation with a real parser one day, but that will take a bit of time to fully implement and test. Unfortunately due to lack of time this can’t be done in the next weeks or months. Besides: The current approach works well in most use cases anyway. Till that day until the existing implementation will be replaced all users of this library will need to get along with the current implementation. Which you will likely find working pretty well until you not run into the following bug:
If a JSON file is provided in a single line not terminated by a line feed, comments in this file will not be parsed.
So use multi-line JSON files please (which you will likely do anyway as comments in JSON files indicate that these files address human beings and therefor will not be single-line-JSON files anyway).
How to use this module
### Import
To import this module use the following statement:
import jk_commentjson
### Parsing
You can parse JSON files like this:
json_loaded = commentjson.loads(json_string)
A JSON file can contain comments of the following style:
line comments using “//” (C-style comments)
line comments using “#” (Python-style comments)
Contact Information
This is Open Source code. That not only gives you the possibility of freely using this code it also allows you to contribute. Feel free to contact the author(s) of this software listed below, either for comments, collaboration requests, suggestions for improvement or reporting bugs:
Jürgen Knauth: jknauth@uni-goettingen.de, pubsrc@binary-overflow.de
License
This software is provided under the following license:
Apache Software License 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file jk_commentjson-0.2017.10.7.tar.gz
.
File metadata
- Download URL: jk_commentjson-0.2017.10.7.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e7b7ab773209e83c27b1bcb12e230652f060e5c9c9c910ea05d741c45ccb4cd |
|
MD5 | 12094b33ebf4ae1afec97be96adffde6 |
|
BLAKE2b-256 | 299dc5708c3e95ee437ac572c3cd862f673dea3beadde8fe59f3e08600f5d223 |