KJSON_ARRAY_OPEN(3)
π KJSON_ARRAY_OPEN(3) β the kcgijson array-scope page, bestie edition π
okay so this is from the Library Functions Manual for KJSON_ARRAY_OPEN(3), and it lives in the library "libkcgijson" π
yes that's libkcgijson, say it with your chest.
β¨ NAME β¨
kjson_array_open, kjson_arrayp_open β open an array scope for kcgijson π
πΈ LIBRARY πΈ
library "libkcgijson" β that's the one, no cap π«Ά
π¦ SYNOPSIS π¦
#include <sys/types.h>
#include <stdarg.h>
#include <stdint.h>
#include <kcgi.h>
#include <kcgijson.h>
enum kcgi_err
kjson_array_open(struct kjsonreq *req);
enum kcgi_err
kjson_arrayp_open(struct kjsonreq *req, const char *name);
like, includes first, then the two functions, both returning enum kcgi_err β got it? iconic. β
π DESCRIPTION π
so basically you're opening an array scope in a context req that was initialised with khtml_open(3). that's the whole vibe. π
scopes get closed with kjson_array_close(3) or kjson_close(3) β you can't just leave them open forever, that's not the energy we're going for π
array scopes may be filled in with un-named values, like when you use kjson_putstring(3) π
okay and here's the distinction, because it matters:
- the
kjson_array_open()form is for array scopes - the
kjson_arrayp_open()form is for objects
and the cute part: passing a NULL value to name for kjson_arrayp_open() is equivalent to calling kjson_array_open(). literally the same thing, they're twins π
π₯ RETURN VALUES π₯
returns an enum kcgi_err indicating the error state. here's the whole roster, no skipping:
KCGI_OKβ success!! not an error!! we love to see it πKCGI_ENOMEMβ internal memory allocation failure, and yes that includes reaching the maximum number of possible JSON scopes. so like, too many scopes = sad. πKCGI_HUPβ the output connection has been terminated. for FastCGI connections, the current connection should be released withkhttp_free(3)and the parse loop reentered. π«ΆKCGI_FORMβ the connection is still expecting headers withkhttp_head(3). this 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 the parse loop reentered. (yes, same drill as above π )KCGI_SYSTEMβ internal system error writing to the output stream. πKCGI_WRITERβ the incorrect form was used for the current scope, for example, an array-type write within an object. like, wrong vibe for the wrong place, bestie π
fr fr read those last two FastCGI ones carefully β release with khttp_free(3) and reenter the parse loop. that's not optional flavour text, that's instructions.
π§ EXAMPLES π§
the following outputs a simple JSON document. it assumes r is a struct kreq pointer. and for brevity, it does not do any error checking β which, okay, fair for a demo, but you know better, right? π
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_array_open(&req);
kjson_putstring(&req, "bar");
kjson_putstring(&req, "baz");
kjson_close(&req);
look at that. headers, body, open, open array, two strings, close. ate and left no crumbs πβ¨
β SEE ALSO β
kcgijson(3) β go read that one too, iykyk πΈ
π AUTHORS π
written by Kristaps Dzonsons <kristaps@bsd.lv>. thank you king π«Άπ
and that's the page!! this version came from Debian, with the date placeholder $Mdocdate$, and the man page title is KJSON_ARRAY_OPEN(3) β mwah, go write some JSON arrays bestie ππ¦π
π¦ 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