KJSON_PUTNULL(3)
π 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 noKCGI_HUPβ the output connection has been terminated. for FastCGI connections, the current connection should be released withkhttp_free(3)and the parse loop reentered. she's gone, bestie πKCGI_FORMβ the connection is still expecting headers withkhttp_head(3). this meanskhttp_body(3)did not return with success or was not invoked. for FastCGI connections, the current connection should be released withkhttp_free(3)and the parse loop reentered. lowkey awkward nglKCGI_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 π§
kcgijson(3)β go read it, iykyk
πΈ 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
- Copyright (c) 2020 Kristaps Dzonsons <kristaps@bsd.lv>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms