Skip to content

Instantly share code, notes, and snippets.

@cellularmitosis

cellularmitosis/README.md

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

EVfljVlX0AIWcdY

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?

jsonc-to-json.sh:

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

Nope. 😎




Might as well throw in an example Makefile 😃:

foo.json: foo.jsonc
	jsonc-to-json.sh foo.jsonc
@patrickmichalina

This comment has been minimized.

Copy link

@patrickmichalina patrickmichalina commented Jun 16, 2020

Nice!

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.