Skip to content

Instantly share code, notes, and snippets.

Last active Aug 20, 2021
What would you like to do?
JSON with comments

Blog 2020/4/13

<- previous | index | next ->

JSON with comments

Recently I saw a thread on twitter about various techniques for hacking comments into JSON:


While this is clever, it... makes me feel icky.

Why was this done? Presumably because creating your own file format ("JSON with comments"), along with a JSON-with-comments to JSON "compiler" which strips the comments out, was seen as being too difficult.

But is it?

# Produces a .json file by stripping the comments from a .jsonc file.
outfile=`basename $infile .jsonc`.json
cat $infile | sed '/[[:space:]]*\/\//d' > $outfile

Nope. 😎

Might as well throw in an example Makefile 😃:

foo.json: foo.jsonc foo.jsonc
Copy link

patrickmichalina commented Jun 16, 2020


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment