Skip to content

Instantly share code, notes, and snippets.

@ghedo
Last active Oct 5, 2015
Embed
What would you like to do?
Stupid JSON prettifier
/*
* Stupid JSON prettifier.
*
* Compile:
* $ cc -o j jsonpretty.c -ljansson
*
* Usage:
* $ ./j < <file>
* $ cat <file> | ./j
*
* Examples:
* $ curl http://example.com/some_file.json | ./j
*
* Copyright (C) 2012 Alessandro Ghedini <alessandro@ghedini.me>
* --------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* Alessandro Ghedini wrote this file. As long as you retain this
* notice you can do whatever you want with this stuff. If we
* meet some day, and you think this stuff is worth it, you can
* buy me a beer in return.
* --------------------------------------------------------------
*/
#include <stdio.h>
#include <jansson.h>
int main(int argc, char *argv[]) {
json_t *root;
json_error_t error;
root = json_loadf(stdin, 0, &error);
if (!root) {
fprintf(stderr, "error: line %d: %s\n", error.line, error.text);
return -1;
}
json_dumpf(root, stdout, JSON_INDENT(2) | JSON_SORT_KEYS);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment