KJSON_STRING_OPEN(3)
okay bestie, welcome to the KJSON_STRING_OPEN(3) page β itβs giving βtiny function, very important JSON businessβ and weβre gonna get you comfy with it π
β¨
πΈ NAME πΈ
kjson_string_open, kjson_stringp_open β open a string scope for kcgijson π
π LIBRARY π
This one lives in the library libkcgijson π¦
β¨ SYNOPSIS β¨
#include <sys/types.h>
#include <stdarg.h>
#include <stdint.h>
#include <kcgi.h>
#include <kcgijson.h>
enum kcgi_err
kjson_string_open(struct kjsonreq *req);
enum kcgi_err
kjson_stringp_open(struct kjsonreq *req, const char *name);
π DESCRIPTION π
So basically: this opens a string scope inside a context req that was initialised with khtml_open(3). Scopes get closed with kjson_string_close(3) or kjson_close(3). String scopes are open strings that may be filled in with further kjson_string_puts(3) and family functions β yes, the whole little string-writing squad π«Ά
The kjson_string_open() form is for array scopes, while kjson_stringp_open() is for objects. Main character energy for both, honestly π
Passing a NULL value to name for kjson_stringp_open() is equivalent to calling kjson_string_open() β literally the same vibe, no cap π
π RETURN VALUES π
This returns an enum kcgi_err, which is your little error-state vibe check:
KCGI_OKβ Success (not an error). Slay βKCGI_ENOMEMβ Internal memory allocation failure, including reaching the maximum number of possible JSON scopes. Memory said βbestie, noβ πKCGI_HUPβ The output connection has been terminated. For FastCGI connections, the current connection should be released withkhttp_free(3)and parse loop reentered. Connection said βIβm outβ π¨KCGI_FORMβ The connection is still expecting headers withkhttp_head(3). Indicates thatkhttp_body(3)did not return with success or was not invoked. For FastCGI connections, the current connection should be released withkhttp_free(3)and parse loop reentered. Header drama, fr fr π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, for example, an array-type write within an object. Wrong vibe for the wrong scope π¨
π§ EXAMPLES π§
The following outputs a simple JSON document. It assumes r is a struct kreq pointer. For brevity, it does not do any error checking β bold move, iconic behavior, but maybe check your errors in real life, bestie π
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_string_open(&req);
kjson_string_puts(&req, "Hello, ");
kjson_string_puts(&req, "world.");
kjson_close(&req);
π SEE ALSO π
kcgijson(3)β go read this too, iykyk πβ¨
π AUTHORS π
Written by Kristaps Dzonsons <kristaps@bsd.lv>. We love a credited icon π«Ά
mwah π this cutie comes from Debian, stamped with $Mdocdate$, and yes bestie, itβs the KJSON_STRING_OPEN(3) page β periodt π
π¦ 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