KJSON_STRING_OPEN(3)

πŸ“¦ version 1.0.1, in alpine 3.24

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 with khttp_free(3) and parse loop reentered. Connection said β€œI’m out” πŸ’¨
  • KCGI_FORM β€” The connection is still expecting headers with khttp_head(3). Indicates that 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 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms