KJSON_PUTNULL(3)

πŸ“¦ version 1.0.1, in alpine 3.24

πŸ’œ KJSON_PUTNULL(3) πŸ’œ

okay so bestie, this is a page from the Library Functions Manual β€” yes, the real one β€” and it's all about kjson_putnull and kjson_putnullp from the libkcgijson library. sit down, grab a lil snack πŸ“, we're learning today.


✨ NAME ✨

kjson_putnull, kjson_putnullp β€” the girlies that put null content for kcgijson. that's it. that's the job. πŸ’…


πŸ“š LIBRARY πŸ“š

library β€œlibkcgijson” β€” that's the one, that's the icon πŸ‘‘


πŸŽ€ SYNOPSIS πŸŽ€

like, the whole vibe, verbatim:

#include <sys/types.h>
#include <stdarg.h>
#include <stdint.h>
#include <kcgi.h>
#include <kcgijson.h>

enum kcgi_err
kjson_putnull(struct kjsonreq *req);

enum kcgi_err
kjson_putnullp(struct kjsonreq *req, const char *name);

πŸ¦‹ DESCRIPTION πŸ¦‹

so the way this works: you write a null to a context req that was initialised with khtml_open(3). yes, khtml_open(3) β€” that's not a typo, that's what the page says, don't come for me πŸ™ˆ

  • the kjson_putnull() form is for array scopes, periodt
  • the kjson_putnullp() form is for objects πŸ’–

and here's the lil gotcha: if you pass a NULL value to name for kjson_putnullp(), that's equivalent to just calling kjson_putnull(). same energy, different name tag 🫢


πŸ”₯ RETURN VALUES πŸ”₯

returns an enum kcgi_err telling you the error state. let's do a vibe check on each one:

  • KCGI_OK β€” success, we ate, this is not an error πŸ’…βœ¨
  • KCGI_ENOMEM β€” internal memory allocation failure 😭 the memory said no
  • KCGI_HUP β€” the output connection has been terminated. for FastCGI connections, the current connection should be released with khttp_free(3) and the parse loop reentered. she's gone, bestie πŸ’€
  • KCGI_FORM β€” the connection is still expecting headers with khttp_head(3). this means khttp_body(3) did not return with success or was not invoked. for FastCGI connections, the current connection should be released with khttp_free(3) and the parse loop reentered. lowkey awkward ngl
  • KCGI_SYSTEM β€” internal system error writing to the output stream. the system is being messy 😀
  • KCGI_WRITER β€” the incorrect form was used for the current scope. like, for example, an array-type write within an object. wrong place, wrong time, wrong scope β€” read the room πŸ™ˆ

🌈 EXAMPLES 🌈

the following outputs a simple JSON document. it assumes r is a struct kreq pointer. and for brevity β€” and because we're being cute and casual β€” it does not do any error checking. no cap, live dangerously πŸ’€

khttp_head(r, kresps[KRESP_STATUS],
  "%s", khttps[KHTTP_200]);
khttp_head(r, kresps[KRESP_CONTENT_TYPE],
  "%s", kmimetypes[KMIME_APP_JSON]);
khttp_body(r);
kjson_open(&req, r);
kjson_obj_open(&req);
kjson_putnullp(&req, "bar");
kjson_close(&req);

look at her go. iconic. "bar" gets a null and honestly? she earned it πŸ‘‘


🧚 SEE ALSO 🧚


🌸 AUTHORS 🌸

written by Kristaps Dzonsons <kristaps@bsd.lv>. we stan a legend 🫢


and that's the whole page, bestie πŸ’– this little cutie came from Debian, version stamp $Mdocdate$, and she lives at KJSON_PUTNULL(3). mwah, go write some JSON βœ¨πŸŽ€

πŸ“¦ where this page comes from
  • alpine 3.24: kcgi-doc 1.0.1-r0 Β· ISC
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms