add JSON_C_TO_STRING_COLOR option

This option enable color in json_object_to_json_string_ext.
I've try to made something similar to jq output,
but I've color true/false and null in purple,
as it's what is common color scheme used in programing language in emacs.

also add a '-c' option into json_parser to test it.

note: that I could have done a color() function similar to
what is done with indent(), but as the code is pretty small
I've keep it as it. so if you want  me to use a subfunction
tell me and I'll do it.

Signed-off-by: Matthias Gatto <matthias.gatto@protonmail.com>
This commit is contained in:
Matthias Gatto
2022-06-02 17:10:21 +02:00
committed by Matthias Gatto
parent bdfdb5fe10
commit 9803032b9d
3 changed files with 60 additions and 10 deletions

View File

@@ -74,6 +74,15 @@ extern "C" {
*/
#define JSON_C_TO_STRING_NOSLASHESCAPE (1 << 4)
/**
* A flag for the json_object_to_json_string_ext() and
* json_object_to_file_ext() functions which causes
* the output to be formatted.
*
* Use color for printing json.
*/
#define JSON_C_TO_STRING_COLOR (1 << 5)
/**
* A flag for the json_object_object_add_ex function which
* causes the value to be added without a check if it already exists.