From cb8c4fceb55e3f6d37e6a76bf3d84f5385bdea72 Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Wed, 8 Mar 2023 04:06:43 +0000 Subject: [PATCH] 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. --- TODO.txt | 2 +- tools/src/json.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tools/src/json.c diff --git a/TODO.txt b/TODO.txt index cb7c0cc..fa07521 100644 --- a/TODO.txt +++ b/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. diff --git a/tools/src/json.c b/tools/src/json.c new file mode 100644 index 0000000..ae8a36f --- /dev/null +++ b/tools/src/json.c @@ -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 + +#include + +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; +}