-
Notifications
You must be signed in to change notification settings - Fork 254
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
New option -j / --json for the JSON output in the functions print_per_system_stats() and print_global_stats() #379
base: develop
Are you sure you want to change the base?
Conversation
Was put on draft because the test is still missing and I wanted to wait for feedback first |
Tested and confirmed working.
Tested various ways, seems to all work the way we need it to. This binary is actually going into production today, with the hopes this will be included in main/master in the future. My C is a little rusty these days but I'm happy to help with this if I can. The only thing I can suggest is adding a \n at the end of the payload because it does this There's also the question of whether you bother pretty printing it or just leaving it condensed (less characters to decode, technically more efficient). Otherwise, perfect fit for us. |
We may have an issue here: fping --json -C 10 -p 1000 -t 2000 -q 8.8.8.8 1.1.1.1returns this:
However when I try to parse it:
Perhaps you should be returning:
This parses as valid JSON and is basically handled the same way, foreach/for/etc over the count object. |
I've attached 3 diff's showing the changes I've made to produce a value JSON object. fping.c.diff.txt New output looks like this:
|
Thanks a lot for this! Before we merge and before further work on the implementation is done, I think that there should be a design and discussion of the json schema. This was already a discussion topic in the previous PR that attempted to implement JSON support. Since this is going to be a sort of API, I want to get it right the first time. In particular what comes to mind:
Can you create maybe a (separate) PR with a markdown file that explains the JSON format? We can then discuss there. |
I have created a discussion #381 |
…_system_stats() and print_global_stats()
bde460c
to
7523994
Compare
A JSON output can be generated using the
-j / --json
option.This can be extended with the
-s
option.The
json.c/.h
are intended to simplify use somewhat.On the one hand, it can be used to control the spaces for the output format and, on the other hand, the separators for the next data record.
The key value function only works with strings. If numbers are used, there is the function
json_int_to_string()