API Reference
The modules below index the API surface of github.com/cybergodev/json in two views: by module and by feature.
Two API styles
Package-level functions (e.g. json.GetString(data, "path")) need no instance; Processor methods (e.g. p.GetString(data, "path")) reuse configuration, the pre-parse cache, and the hook system. For choosing between them, see the decision tree in the Processor Guide.
Module Index
Function APIs
| Module | Description |
|---|---|
| Package Functions | Package-level function reference (query/modify/delete/encode/parse/batch/JSONL/file/iteration) |
| Processor | Processor methods (mirrors the package functions, plus lifecycle and pre-parsing) |
Types and Interfaces
| Module | Description |
|---|---|
| Config | Configuration options in detail (DefaultConfig / SecurityConfig / PrettyConfig) |
| Type Definitions | Core types (Config / Schema / Stats / AccessResult, plus Encoder / Decoder, CompiledPath / PathSegment) |
| Interface Definitions | Extension interfaces (Hook / PathParser take effect; CustomEncoder / Validator are deprecated) |
| Iterators and IterableValue | Iterator / BatchIterator / ParallelIterator / StreamIterator types |
| Generic Operations | Generic APIs (GetTyped[T] / StreamLinesInto[T] / Result[T]) |
| Constants and Errors | Constants and error types (including Default* constants and a Config field mapping table) |
Utilities and Helpers
| Module | Description |
|---|---|
| Helper Functions | CompareJSON / MergeJSON, cache management, the global processor, SafeError / RedactedPath, AccessResult methods |
| Formatted Output | Pretty vs compact output, incl. Print-family migration notes |
Cross-Module Topics
| Module | Description |
|---|---|
| Streaming | Large-file guide (full-load vs streaming iteration) |
| JSONL / NDJSON Streaming | Streaming reads and writes with the StreamJSONL family and JSONLWriter |
| Security Validation | Security-mode API (SecurityConfig / DangerousPattern / RegisterDangerousPattern) |
| Schema Validation | Schema validation (ValidateSchema / DefaultSchema / NewSchema) |
| Hook System | Operation interception hooks (LoggingHook / TimingHook / ValidationHook / ErrorHook) |
| Custom Encoders | Custom encoding via MarshalJSON / MarshalText (the CustomEncoder / TypeEncoder interfaces are deprecated) |
Quick Lookup
By Feature
Path Queries
| Function | Description |
|---|---|
Get, GetWithContext, GetString, GetInt, GetFloat, GetBool, GetArray, GetObject | Type-safe gets |
GetTyped[T] | Generic get |
SafeGet | Safe get returning an AccessResult |
GetMultiple | Batch get |
Modification Operations
| Function | Description |
|---|---|
Set, SetMultiple | Set values |
SetCreate, SetMultipleCreate | Set values with automatic path creation |
Delete, DeleteClean | Delete values |
ProcessBatch | Batch operations |
Encoding and Decoding
| Function | Description |
|---|---|
Marshal, Unmarshal | Same signatures as encoding/json, optional cfg; default input is security-validated, with minor behavior differences |
MarshalIndent | Indented encoding, same signature as encoding/json.MarshalIndent, optional cfg |
Encode, EncodePretty | Encode to string (with config / pretty output) |
EncodeWithConfig (deprecated) | Functionally equivalent to Encode, retained within v1 — use Encode or Marshal in new code |
NewEncoder, NewDecoder | Streaming encode/decode |
Parse, ParseAny | Parse into a target variable / parse as any |
EncodeBatch, EncodeFields, EncodeStream | Encode key-value pairs into an object / encode selected fields / encode multiple values into an array |
Formatting
| Function | Description |
|---|---|
Prettify | Pretty-print JSON |
Compact | Compact JSON (buffer form, same signature as encoding/json.Compact) |
CompactString | Compact JSON (string in/out form, mirrors Processor.Compact) |
Indent | Indent and write to a buffer (same signature as encoding/json.Indent) |
HTMLEscape | Escape HTML characters into a buffer (same signature as encoding/json.HTMLEscape) |
File Operations
| Function | Description |
|---|---|
LoadFromFile, SaveToFile | Read and write files |
LoadFromReader | Read from a Reader |
MarshalToFile, UnmarshalFromFile | File encode/decode |
SaveToWriter | Write to any Writer |
Iteration and Traversal
| Function | Description |
|---|---|
Foreach (deprecated), ForeachWithError, ForeachNested (deprecated), ForeachNestedWithError | Iterate arrays/objects (incl. deep traversal; the void variants are deprecated — prefer *WithError) |
ForeachWithPath, ForeachWithPathAndIterator, ForeachWithPathAndControl | Iterate at a given path (carrying the current path / with break control) |
ForeachReturn | Iterate and return the modified JSON |
ForeachFile, ForeachFileWithPath, ForeachFileChunked, ForeachFileNested | Item-by-item file iteration (fully loaded, then item-by-item/batched callbacks) |
NewIterator, NewBatchIterator, NewParallelIterator, NewStreamIterator | Standalone iterator constructors (see Iterators) |
Cache and Globals
| Function | Description |
|---|---|
WarmupCache, ClearCache | Cache warm-up / clearing |
GetStats, GetHealthStatus | Runtime statistics / health check |
GetConfig, SetLogger | Read processor config / inject a logger (both global and Processor methods) |
SetGlobalProcessor, ShutdownGlobalProcessor | Replace and shut down the global processor |
RegisterDangerousPattern, UnregisterDangerousPattern, ListDangerousPatterns | Global dangerous-pattern registry register / remove / list (see Helper Functions) |
CompilePath (Processor), PreParse (Processor) | Path pre-compilation / JSON pre-parsing |
Streaming
| Type/Method | Description |
|---|---|
StreamLinesInto[T] | Stream JSONL from a Reader and convert to []T |
ParseJSONL | Parse JSONL bytes into []any |
ToJSONL, ToJSONLString | Convert []any to JSONL format |
JSONLWriter | JSONL writer (Write/WriteAll/WriteRaw) |
NDJSONProcessor (deprecated) | NDJSON/JSONL processor (created by NewNDJSONProcessor; use the StreamJSONL family in new code) |
ForeachFile | Item-by-item file iteration (whole file loaded) |
Validation
| Function | Description |
|---|---|
Valid | JSON validation, same signature as encoding/json.Valid |
ValidWithConfig | JSON validation with config |
ValidateSchema | Schema validation (used with the Schema type) |
CompareJSON | Compare JSON for equivalence |
MergeJSON, MergeMany | JSON merging (union/intersection/difference modes, see Helper Functions) |
Naming Conventions
| Pattern | Description | Example |
|---|---|---|
Get{Type} | Get as the given type, with optional defaultValue | GetString, GetInt |
GetTyped[T] | Generic get, returns T | GetTyped[User] |
New{Type} | Create an instance | New (returns *Processor), NewEncoder |
Default{Type} | Default configuration | DefaultConfig |
{Type}Config | Configuration preset | SecurityConfig, PrettyConfig |
Foreach* | Iteration variants (WithError / WithPath / Nested / File) | ForeachNestedWithError |
Stream* | Streaming variants (Into / Parallel / File / Chunked) | StreamJSONLParallel |
{Verb}Hook | Hook factories | LoggingHook, ValidationHook |
See Also
- Quick Start: installation and basic usage
- Processor Guide: when to use a processor
- Path Expression Syntax: path query syntax
- Examples: runnable code samples
- Large File Handling: streaming guide