Last active
October 5, 2015 09:07
-
-
Save ghedo/2783919 to your computer and use it in GitHub Desktop.
Stupid JSON prettifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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