FEATURE: Type and Conversion Builtins
| Field | Value |
|---|---|
| Version | 20261028 V1 |
| Description | Inspect jq values and convert among numeric, Boolean, string, JSON, and Unicode representations. |
| Depends On | FEATURE-GeneratorControl.md |
| Provides | jq type and conversion builtins |
| Consumes | jq reductions and generator control |
Purpose
Expose jq's type and conversion filters to programs, using the manual and corpus as the behavioral authority.
Behavior
Implement type, length, utf8bytelength, tonumber, toboolean, tostring, tojson, fromjson, explode, and implode, including their specified input types and errors. String length counts Unicode codepoints; UTF-8 byte length counts encoded bytes. Preserve jq's conversion and serialization behavior, including non-decnum numeric behavior and special numeric values. Unicode conversion follows jq's replacement behavior for invalid codepoints. Errors caught by jq programs are values and must match the corpus where it specifies them.
Programmatic Acceptance
=== AC conversion-conformance ===
Intent: Type, length, conversion, and Unicode filters execute their applicable corpus cases.
Suite: scoped
Requires: executable=python3; scope=test
Probe: --list
Probe Count: summary
import json import os import subprocess import sys
SELECT = r"^(?:utf8bytelength|\[\.\[\] \| length\]|\[\.\[\] \| try utf8bytelength catch \.\]|implode\|explode|fromjson \| isnan|tojson \| fromjson)$" result = subprocess.run( [sys.executable, "sources/run_conformance.py", "--select", SELECT, "--json"], capture_output=True, text=True, env={**os.environ, "JQ": os.path.abspath("jq")}, ) print(result.stdout) print(result.stderr, file=sys.stderr) report = json.loads(result.stdout) tally = report["summary"] assert sum(tally.values()) > 0, SELECT assert tally["fail"] == 0 and tally["error"] == 0, tally assert result.returncode == 0, result.returncode === END AC conversion-conformance ===
User Acceptance
- None.
Guardrails
- Do not mutate any file under
sources/. - Use Python's standard library only.
- Cross-feature cases requiring later builtins remain covered by scoped integration.