This article was originally posted on Techiediaries.
JSON doesn’t permit comments by design. As explained by its creator Douglas Crockford.
I removed comments from JSON because I saw people were using them to hold parsing directives, a practice which would have destroyed interoperability.
But he also stated that you can use external or built-in tools to pre-parse JSON files and remove any comments before the actual parsing takes place.
In this short article, we’ll see how you can remove comments from JSON files using Python code.
First, we need to be able to read JSON files in our Python code:
import json
with open('example.json') as json_file:
data = json.load(json_file)
print(data)
#python #json