Nicolas George (12023-04-28): > Signed-off-by: Nicolas George > --- > libavutil/Makefile | 1 + > libavutil/json.c | 368 +++++++++++++++++++++++++++++++++++ > libavutil/json.h | 470 +++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 839 insertions(+) > create mode 100644 libavutil/json.c > create mode 100644 libavutil/json.h I forgot to write: I wrote this code not only because we have half-baked JSON output in multiple places in the code, but also to show the kind of API AVWriter makes possible. Typical JSON APIs would have a function to write a string value or an object key, requiring the caller to build the string beforehand. Of course, this API can do that: > +void av_json_add_string(AVJson *jc, const char *str); including with a format string, which is less usual: > +void av_json_add_string_printf(AVJson *jc, const char *fmt, ...) av_printf_format(2, 3); But these are just wrappers for convenience over the real API: > +AVWriter av_json_begin_string(AVJson *jc); It starts a string, i.e. outputs a quote, and then we get a writer to write into that string. It will be automatically escaped, no intermediate buffer will be used, and all the functions of the writer API are available, including all the av_something_write() to come to serialize our various types. Also note that this API as a whole can produce small JSON outputs without any dynamic allocation, making it suitable for once-per-frame calls, but is not limited to that. Do we *need* that: of course not, we still put “len += snprintf()” and “av_realloc()” and error checks all over the place. Now, while people maybe look at the code, there are a few things I can work on, and I wonder which one you would like to see first: - Finishing this JSON API. - A XML API: that would be useful for dashenc, movenc, ttmlenc, ffprobe and possibly others. - Add serialization functions for our various types, like I did for av_disposition_write(). - Go forward with the others API enhancements that I promised and that depend on AVWriter. Regards, -- Nicolas George