On Tue, 2024-03-05 at 14:32 +0300, Isaev Ruslan wrote: > > I think i could make a universal printf() like function with > additional args for json representation. > > Something like this: > before: > printf("\t * Manufacturer: %.*s\n", sublen, data + 4); > > after: > printf_json("\t * Manufacturer", "%.*s", sublen, data + 4); I think you meant printf_json("Manufacturer", "%.*s", sublen, data + 4); but yeah, that seems better? Not sure I'd call it print_json() over just print() or output() or so at that point. > void printf_json(const char* key, const char* fmt, ...) { > char buf[1024]; > va_list args; > va_start(args, format); > > if (iw_json) { > vsnprintf(buf, sizeof(buf), format, args); > print_string(PRINT_JSON, key, "%s", buf); > } else { > printf("\t * %s: ", key); Guess we'd have to be careful about the indentation. Track the (JSON) object nesting level and apply it that way? johannes