KCGIJSON(3)

πŸ“¦
version 1.0.1 Β· 2 versions
, in alpine 3.24

πŸ’– KCGIJSON(3) β€” Library Functions Manual πŸ’–

okay bestie, meet kcgijson β€” the JSON-output helper for kcgi, and yes it’s giving very useful utility energy πŸ’…βœ¨


🌟 NAME 🌟

kcgijson β€” JSON output for kcgi


πŸŽ€ LIBRARY πŸŽ€

library β€œlibkcgijson”


✨ SYNOPSIS ✨

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

πŸ¦‹ DESCRIPTION πŸ¦‹

So this is how you produce output of JSON objects and arrays inside a kcgi(3) context that was allocated with khttp_parse(3). iconic, honestly.

To compile and link, use pkg-config(1) like this:

% cc `pkg-config --cflags kcgi-json` -c sample.c
% cc -o sample sample.o `pkg-config --libs kcgi-json`

All kcgijson functions accept a struct kjsonreq object. To use this properly, open a context with kjson_open(3), add content, then end with kjson_close(3). that’s the whole ritual, bestie 🫢


🌈 EXAMPLES 🌈

Let struct kreq *r already be initialised, and the request be for KMIME_APP_JSON. The following fragment prints out a simple JSON object. Error checking is omitted for brevity.

kjson_open(&req, r);
kcgi_writer_disable(r);
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_objp_open(&req, "anobj");
kjson_putstringp(&req, "astring", "baz");
kjson_putintp(&req, "anint", 12345);
kjson_stringp_open(&req, "alongstring");
kjson_string_puts(&req, "hello, ");
kjson_string_puts(&req, "world.");
kjson_string_close(&req); /* alongstring */
kjson_arrayp_open(&req, "anarray");
kjson_putint(&req, 1);
kjson_putint(&req, 2);
kjson_putdouble(&req, 3.0);
kjson_array_close(&req); /* anarray */
kjson_obj_close(&req); /* anobj */
kjson_close(&req);
Following the kcgi_writer_disable(3) call, no further writers may be allocated. that’s a hard rule, no cap πŸš«πŸ’€

πŸ”₯ SEE ALSO πŸ”₯


πŸ‘‘ STANDARDS πŸ‘‘

The kcgijson functions conform to the ECMA-404 JSON Data Interchange Standard, also documented as RFC 7159. Parts of this document reference ECMAScript 5, commonly known as JavaScript. standards queen behavior, honestly ⭐


πŸ’œ AUTHORS πŸ’œ

Written by Kristaps Dzonsons <kristaps@bsd.lv>.


This page was served fresh by Debian, stamped with $Mdocdate$, and filed under KCGIJSON(3) β€” bye bestie, go make some iconic 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