git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[GSoC PATCH v2 2/2] json-writer: describe the usage of jw_* functions

From
Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Date
May 12, 2025, 02:09 UTC
Message-ID
<20250512020935.73140-3-lucasseikioshiro@gmail.com>
In-Reply-To
<20250512020935.73140-1-lucasseikioshiro@gmail.com>

Provide an overview of the set of functions used for manipulating json_writers by describing what functions should be used for each JSON-related task.

Helped-by: Junio C Hamano <gitster@pobox.com>
Mentored-by Patrick Steinhardt <ps@pks.im>
Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
 json-writer.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
diff --git a/json-writer.h b/json-writer.h
index aa513e86cb..8b7470af67 100644
--- a/json-writer.h
+++ b/json-writer.h
@@ -28,6 +28,34 @@
  * object/array) -or- by building them inline in one pass.  This is a
  * personal style and/or data shape choice.
  *
+ * USAGE:
+ * ======
+ *
+ * - Initialize the json_writer with jw_init.
+ *
+ * - Open an object as the main data structure with jw_object_begin.
+ *   Append a key-value pair to it using the jw_object_<type> functions.
+ *   Conclude with jw_end.
+ *
+ * - Alternatively, open an array as the main data structure with
+ *   jw_array_begin. Append a value to it using the jw_array_<type>
+ *   functions. Conclude with jw_end.
+ *
+ * - Append a new, unterminated array or object to the current
+ *   object using the jw_object_inline_begin_{array, object} functions.
+ *   Similarly, append a new, unterminated array or object to
+ *   the current array using the jw_array_inline_begin_{array, object}
+ *   functions.
+ *
+ * - Append other json_writer as a value to the current array or object
+ *   using the jw_{array, object}_sub_jw functions.
+ *
+ * - Extend the current array with an null-terminated array of strings
+ *   by using jw_array_argv or with a fixed number of elements of a
+ *   array of string by using jw_array_argc_argv.
+ *
+ * - Relase the json_writer after using it by calling jw_release.
+ *
  * See t/helper/test-json-writer.c for various usage examples.
  *
  * LIMITATIONS:
-- 
2.39.5 (Apple Git-154)
Previous: Karthik NayakNext: Patrick Steinhardt
Message 7 of 12 in “json-writer: describe the jw_* functions”
  1. 0/2 json-writer: describe the jw_* functionsLucas Seiki Oshiro, May 12, 2025
  2. 1/2 json-writer: add docstrings to jw_* functionsLucas Seiki Oshiro, May 12, 2025
  3. Patrick SteinhardtMay 12, 2025
  4. Lucas Seiki OshiroMay 13, 2025
  5. Patrick SteinhardtMay 14, 2025
  6. Karthik NayakMay 12, 2025
  7. 2/2 json-writer: describe the usage of jw_* functionsLucas Seiki Oshiro, May 12, 2025
  8. Patrick SteinhardtMay 12, 2025
  9. Karthik NayakMay 12, 2025
  10. Lucas Seiki OshiroMay 13, 2025
  11. Patrick SteinhardtMay 14, 2025
  12. Karthik NayakMay 12, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.