Skip to content

Instantly share code, notes, and snippets.



Last active Jun 16, 2020
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

This comment has been minimized.

Copy link

@patrickmichalina patrickmichalina commented Jun 16, 2020


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.