2

I've taken a look at the responses in Can comments be used in JSON? about commenting json files, and the general consensus is either

  • don't
  • use data as comments
  • write comment and minify them

I'd like to do the third approach if possible, but it seems that googling for a json minifier other than the standard javascript one is a worthless approach to the problem.

Is there any json minifier library for c? I strongly prefer not to write one myself.

Thanks,

Community
  • 1
  • 1
Blake
  • 695
  • 9
  • 23

1 Answers1

3

Most JSON libraries can do both reading (decoding or parsing JSON) and writing (encoding or printing JSON). Several have some options (e.g. indent or not) for printing. So just read your JSON data, and print it with appropriate flags. This should "minify" the JSON

For the JANSSON library see the flag JSON_COMPACT to json_dumpf (and, as you commented, JSON_DECODE_ANY for json_loads)

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • While not correct, your answer is actually very useful (first of all: I happen to be using jansson, so this is nice). `JSON_COMPACT` Only turns the output format from `key: value` to `key:value`. However, the flags do seem to be what I'm looking for. If I want to parse a json file and ignore comments, I probably want to `json_loads()` with the `JSON_DECODE_ANY` flag. I no longer need this, so won't test it, but if you would like to edit your answer I'll accept it. Thanks again. – Blake Sep 11 '14 at 08:08