$ show jqlang/jq
jq is a compiled, dependency-light C command-line tool and embeddable libjq library for transforming JSON and text streams. In production it acts as a Unix pipeline filter: it reads JSON, raw text, or JSON text sequences from stdin/files, parses them, evaluates a user-supplied filter expression, and writes transformed output to stdout. The filter language is a functional DSL compiled to a custom bytecode via a Flex lexer (src/lexer.l), Bison grammar (src/parser.y), block-based compiler (src/compile.c), and stack VM (src/execute.c) with tail-call optimization. JSON values are represented by the refcounted jv API (src/jv.c, src/jv.h), with carefully maintained UTF-8 handling and exact decimal parsing.
The LLM identified 4 files worth highlighting for reuse:
Core JSON value model for jq. Provides refcounted strings, arrays, objects, and numbers, object construction/lookup, concatenation, splitting, and error propagation via an invalid sentinel value. The public jv.h API makes this the cleanest reusable piece: it could be extracted as a general-purpose C JSON value library, and its explicit jv_copy/jv_free ownership discipline is a model for C APIs.
Self-contained UTF-8 handling: decodes and encodes codepoints, validates sequences, and replaces malformed bytes with U+FFFD. This solves a recurring problem for C tools that parse or emit JSON, and the file is isolated enough to drop into any parser or I/O layer needing robust Unicode normalization.
Vendored David M. Gay dtoa implementation, adapted with portability and threading macros. It provides correctly rounded decimal<->binary conversion for JSON numbers, preserving round-trip fidelity. Heavily specialized but battle-tested and independently reusable in any language runtime or parser needing exact float formatting.
jq's module system: resolves import/include directives across -L paths and JQ_LIBRARY_PATH, topologically loads .jq/.json dependencies, caches loaded modules, and rejects circular imports. The design is a compact reference for adding module semantics to a scripted DSL runtime.