Re: [jansson-users] Re: How to know size in bytes of encoded json object

38 views
Skip to first unread message

Petri Lehtinen

unread,
Jul 5, 2020, 11:27:11 AM7/5/20
to jansso...@googlegroups.com
Hi!

You can use strlen(pPktOut) to get the length of the JSON.

Petri 


alberto cirillo <cirillo...@gmail.com> kirjoitti 5.7.2020 kello 11.49:


Just to be clearer, the json_dumps method returns the JSON representation of root as a string. How could I know the length of the string (i.e. the amount of bytes of the json)?

Il giorno domenica 5 luglio 2020 10:44:08 UTC+2, alberto cirillo ha scritto:
Using the example reported below, I should send on a socket the built JSON object but to do that I need its exact amount of bytes. Is there a way to know the size of the root object (or, in case of a json_dumps, the size of the returned area)?
 
======= EXAMPLE
json_t* root = json_object();

json_object_set_new(root, "test1", json_string("TEST"));
json_object_set_new(root, "test2", json_integer(1));
json_object_set_new(root, "test3", json_integer(1));

pPktOut = json_dumps(root, 0);

json_decref(root);
=====

Thanks

--
--
Jansson users mailing list
jansso...@googlegroups.com
http://groups.google.com/group/jansson-users
---
You received this message because you are subscribed to the Google Groups "Jansson users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jansson-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jansson-users/344398ba-1ca5-47fb-9407-be2f1b61b20bo%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages