forked from lda/telodendria
Begin working on JSON CLI tool.
This is a similar situation to the HTTP CLI tool: since we have the Json API anyway, we might as well have a little command line tool to replace jq.
This commit is contained in:
parent
19e89110cd
commit
cb8c4fceb5
2 changed files with 46 additions and 1 deletions
2
TODO.txt
2
TODO.txt
|
@ -25,7 +25,7 @@ Milestone: v0.3.0
|
|||
[~] Simple command line tool to make matrix requests
|
||||
[x] Built on HTTP client API
|
||||
[ ] http man page
|
||||
[ ] Simple command line tool for working with JSON
|
||||
[~] Simple command line tool for working with JSON
|
||||
- Like a simpler version of jq
|
||||
- Should pretty-print Json
|
||||
- Should be able to query fields for use in shell scripts.
|
||||
|
|
45
tools/src/json.c
Normal file
45
tools/src/json.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation files
|
||||
* (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Json.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
HashMap *json;
|
||||
|
||||
json = JsonDecode(stdin);
|
||||
|
||||
if (!json)
|
||||
{
|
||||
fprintf(stderr, "Malformed JSON.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
JsonEncode(json, stdout);
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue