yyjson

Parse, create, and modify JSON documents in C using the yyjson library.

1.0k|108|Updated Nov 20, 2020
One-click install
npx skills add https://github.com/LuisaGroup/LuisaCompute --skill yyjson
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: yyjson
Source: https://github.com/LuisaGroup/LuisaCompute/tree/main/.agents/skills/yyjson
Command: npx skills add https://github.com/LuisaGroup/LuisaCompute --skill yyjson

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Working with JSON in C requires careful handling of parsing, memory management, and serialization. This Skill provides a complete reference for using yyjson, the single-header ANSI C JSON library bundled in LuisaCompute, covering both immutable and mutable document models.

Core Features & Use Cases

  • JSON Reading and Access: Parse JSON from strings, files, or streams with configurable read flags, then query values via type checks, getters, and iterators.
  • JSON Creation and Modification: Build and edit documents with the mutable API, including array/object manipulation, JSON Pointer operations, and RFC 6902/7386 patching.
  • Serialization and Memory Control: Write minified or pretty-printed JSON with custom allocators, including LuisaCompute's allocator integration pattern.
  • Use Case: Read a configuration file with yyjson_read_file, convert it to a mutable document, remove null entries with an iterator, and write the result back with pretty formatting.

Quick Start

Show me how to read a JSON file with yyjson, modify a value, and write it back with pretty printing.

Frequently Asked Questions about yyjson

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I parse JSON in C with yyjson?

Call yyjson_read with your buffer and length, or yyjson_read_file for file input, to get an immutable yyjson_doc. Access the root with yyjson_doc_get_root, then use type checks and getters like yyjson_get_str or yyjson_obj_get to read values.

How do I modify a JSON document with yyjson?

Convert the immutable document with yyjson_doc_mut_copy, then use mutable APIs like yyjson_mut_obj_add, yyjson_mut_arr_append, or yyjson_mut_doc_ptr_set. Note that a mutable value can only belong to one container at a time.

Does yyjson support custom memory allocators?

Yes, yyjson accepts a custom yyjson_alc with malloc, realloc, and free signatures passed to read and write functions. LuisaCompute forwards allocations to luisa::detail allocator functions with 16-byte alignment.

Why is yyjson object key lookup slow?

yyjson stores arrays and objects as linked lists, so index and key lookups are O(n). For repeated access, prefer iterators like yyjson_arr_iter or yyjson_obj_iter, or the yyjson_arr_foreach and yyjson_obj_foreach macros.

Does yyjson support JSON Pointer and JSON Patch?

Yes, yyjson implements RFC 6901 JSON Pointer via yyjson_doc_ptr_get and mutable set/add/remove variants, plus RFC 6902 JSON Patch via yyjson_patch and RFC 7386 Merge Patch via yyjson_merge_patch.