0

In the Current code i'm using json-c. i'm migrating to jansson. need an equivalent api in jansson which converts the json_object_to_json_string. i found one but it needs a json string object otherwise it is returning null.

const char *json_string_value(const json_t *string) - not working

but my input is a JSON object not a JSON string

sample:

json_object *jobj = json_object_new_object();

....

const char *final_string = json_object_to_json_string(jobj);

Thanks.

ArunPratap
  • 4,816
  • 7
  • 25
  • 43
Sridhar
  • 1
  • 2

1 Answers1

1

I was in your position just recently, I believe the function you are looking for is:

char *json_dumps(const json_t *json, size_t flags)

Returns the JSON representation of json as a string, or NULL on error. flags is described above. The return value must be freed by the caller using free().

https://jansson.readthedocs.io/en/2.8/apiref.html#c.json_dumps

Community
  • 1
  • 1