akheron / jansson

C library for encoding, decoding and manipulating JSON data
http://www.digip.org/jansson/
Other
3.02k stars 807 forks source link

json_dumps can only convert objects #645

Closed janflyborgw closed 1 year ago

janflyborgw commented 1 year ago

I have the need to convert instances of json_t into their corresponding textual JS representation. For instance:

char *s = json_dumps(json_string("An example string"), JSON_COMPACT); char *s = json_dumps(json_true(), JSON_COMPACT);

should give the string "An example string" and the string true

But it seems like json_dumps can only handle objects and I guess this is by design, but is there another way to accomplish this, (apart from implementing it myself)?

janflyborgw commented 1 year ago

Got it. Found the JSON_ENCODE_ANY flag. Sorry for the confusion.