scan_jsonescape(3)

✨ scan_jsonescape(3) β€” parse JSON escaped string ✨

okay bestie, buckle up πŸ’– this one lives in the Library Functions Manual, section 3, and it's literally here to un-escape JSON strings for you. no cap.


🌸 NAME 🌸

scan_jsonescape β€” parse JSON escaped string πŸ¦‹


πŸŽ€ SYNTAX πŸŽ€

#include <libowfat/textcode.h>

size_t scan_jsonescape(const char *src,char *dest,size_t* destlen);

πŸ’… DESCRIPTION πŸ’…

so scan_jsonescape reads JSON-escaped text out of src and drops it into dest, leaving you with a whole UTF-8 string in there. it's giving translator energy 🌈.

parsing stops at any of these three things, periodt:

  • the 0 terminator
  • invalid input characters
  • a double quote that was not escaped

once it's done, it writes the number of bytes sitting in dest into *destlen, and it returns the number of bytes it decoded from src. two numbers, one call, iconic πŸ‘‘

the lowkey chaotic part (in a good way):

  • dest can be NULL πŸ™ˆ
  • destlen can be NULL πŸ™ˆ
  • dest can be src (yes, in-place, she contains multitudes)
to make sure dest is big enough, you've got two options, bestie: either allocate strlen(src)+1 bytes, or call scan_jsonescape twice β€” the first time with dest == NULL, and *destlen will still be written. that's the trick, iykyk 🧚

⭐ RETURN VALUE ⭐

scan_jsonescape returns the number of bytes successfully parsed from src. that's it, that's the number πŸ’œ


πŸ“ EXAMPLES πŸ“

scan_jsonescape("test\n\");",buf,&i) -> return 6, i=5, buf="test\n".

look at her go ✨ return 6, i=5, and buf="test\n". ate, no crumbs.


πŸ”₯ SEE ALSO πŸ”₯


and that's the whole page, bestie 🫢 β€” scan_jsonescape(3) from the Library Functions Manual, page 3, signed off with love and zero crumbs πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from