akheron / jansson

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

Return key length in `json_object_foreach` #581

Closed gonzus closed 3 years ago

gonzus commented 3 years ago

On every iteration, this macro returns the object key in a const char* variable. This means that, if the length of this key is required, one needs to call strlen on the key. Would it be possible to add a way to retrieve the key string and its length (which I assume is known inside the library)?

I am not providing any examples because I am not sure what such an API would look like ideally.

akheron commented 3 years ago

The master branch has json_object_keylen_foreach for this use case.

gonzus commented 3 years ago

Fantastic, will migrate to that as soon as there is a release. Closing the issue.