json_array_append_new with json_pack failure

51 views
Skip to first unread message

Gavin Henry

unread,
Mar 1, 2022, 5:18:32 AM3/1/22
to Jansson users
Hi all,

I'm new to jansson and I have this issue:


It seems json_pack is failing so NULL can't be appended to my array. That sound right?


I'm giving json_pack non-null data, so I'm not sure why it can't put it in a json string.

I'll add the error type check, but when I've done that before it doesn't show much.

Thanks.


Gavin Henry

unread,
Mar 1, 2022, 5:30:35 AM3/1/22
to Jansson users
So I've added the error type check:

if (json_array_append_new(
json_arr,
json_pack("{s:s,s:s,s:s}", "called_number",

phone_numbers[row_num]
->called_number,
"seen_last",
phone_numbers[row_num]->seen_last,
"seen_count",
phone_numbers[row_num]->seen_count,
&error)) != EXIT_SUCCESS) {
fprintf(stderr,
"Failed to append called_number to json array\n");
fprintf(stderr, "Error: %s\n", error.text);

Add I just get:

Failed to append called_number to json array
Error: ?

Gavin Henry

unread,
Mar 1, 2022, 5:33:31 AM3/1/22
to Jansson users
Digging in with gdb to check out data.

Graeme Smecher

unread,
Mar 9, 2022, 3:16:01 AM3/9/22
to jansso...@googlegroups.com
Hi Gavin,

Your interpretation (json_pack fails, and the failure cascades into
json_array_append_new() via a NULL result) seems logical. To get more
meaningful insight, try json_pack_ex() instead of json_pack(). This call
accepts an error object and will give you hints at the point of failure.

The debug messages on your GitHub issue (
https://github.com/SentryPeer/SentryPeer/issues/28) show what looks like
garbage inputs just prior to the error from Jansson. Is it possible that
your test data includes invalid Unicode and Jansson is correctly
complaining about it?

best,
Graeme
> --
> --
> Jansson users mailing list
> jansso...@googlegroups.com
> http://groups.google.com/group/jansson-users
> <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
> <mailto:jansson-user...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jansson-users/ac2bba2c-35ff-47d5-8b85-b428813d983cn%40googlegroups.com
> <https://groups.google.com/d/msgid/jansson-users/ac2bba2c-35ff-47d5-8b85-b428813d983cn%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages