Skip to content

API Reference ​

This section provides the complete API reference for the github.com/cybergodev/json library.

Two API styles

The library offers two API surfaces: package-level functions (e.g. json.GetString(data, "path"), no instance required) and Processor methods (e.g. p.GetString(data, "path"), with configuration reuse, pre-parse caching, and the hook system). Not sure which to use? See the decision tree in the Processor Guide.

Module Index ​

Function APIs ​

ModuleDescription
Package FunctionsPackage-level function reference (query/modify/delete/encode/parse/batch/JSONL/file/iteration)
ProcessorProcessor methods (mirrors the package functions, plus lifecycle and pre-parsing)

Types and Interfaces ​

ModuleDescription
ConfigConfiguration options in detail (DefaultConfig / SecurityConfig / PrettyConfig)
Type DefinitionsCore types (Config / Schema / Stats / AccessResult, plus Encoder / Decoder, CompiledPath / PathSegment)
Interface DefinitionsExtension interfaces (CustomEncoder / Validator / Hook / PathParser)
Iterators and IterableValueIterator / BatchIterator / ParallelIterator / StreamIterator types
Generic OperationsGeneric APIs (GetTyped[T] / StreamLinesInto[T] / Result[T])
Constants and ErrorsConstants and error types (including Default* constants and a Config field mapping table)

Utilities and Helpers ​

ModuleDescription
Helper FunctionsCompareJSON / MergeJSON, cache management, the global processor, SafeError / RedactedPath, AccessResult methods
Formatted OutputPretty vs compact output, incl. Print-family migration notes

Cross-Module Topics ​

ModuleDescription
StreamingLarge-file guide (full-load vs streaming iteration)
JSONL / NDJSON StreamingStreaming reads and writes with the StreamJSONL family and JSONLWriter
Security ValidationSecurity-mode API (SecurityConfig / DangerousPattern / RegisterDangerousPattern)
Schema ValidationSchema validation (ValidateSchema / DefaultSchema / NewSchema)
Hook SystemOperation interception hooks (LoggingHook / TimingHook / ValidationHook / ErrorHook)
Custom EncodersCustom encoders (CustomEncoder / TypeEncoder)

Quick Lookup ​

By Feature ​

Path Queries ​

FunctionDescription
Get, GetWithContext, GetString, GetInt, GetFloat, GetBool, GetArray, GetObjectType-safe gets
GetTyped[T]Generic get
SafeGetSafe get returning an AccessResult
GetMultipleBatch get

Modification Operations ​

FunctionDescription
Set, SetMultipleSet values
SetCreate, SetMultipleCreateSet values with automatic path creation
Delete, DeleteCleanDelete values
ProcessBatchBatch operations

Encoding and Decoding ​

FunctionDescription
Marshal, UnmarshalStandard encode/decode (encoding/json compatible, optional cfg)
MarshalIndentIndented encoding (encoding/json.MarshalIndent compatible, optional cfg)
Encode, EncodePrettyEncode to string (with config / pretty output)
EncodeWithConfig (deprecated)Functionally equivalent to Encode, retained within v1 — use Encode or Marshal in new code
NewEncoder, NewDecoderStreaming encode/decode
Parse, ParseAnyParse into a target variable / parse as any
EncodeBatch, EncodeFields, EncodeStreamEncode key-value pairs into an object / encode selected fields / encode multiple values into an array

Formatting ​

FunctionDescription
PrettifyPretty-print JSON
CompactCompact JSON (buffer form, encoding/json.Compact compatible)
CompactStringCompact JSON (string in/out form, mirrors Processor.Compact)
IndentIndent and write to a buffer (encoding/json.Indent compatible)
HTMLEscapeEscape HTML characters into a buffer (encoding/json.HTMLEscape compatible)

File Operations ​

FunctionDescription
LoadFromFile, SaveToFileRead and write files
LoadFromReaderRead from a Reader
MarshalToFile, UnmarshalFromFileFile encode/decode
SaveToWriterWrite to any Writer

Iteration and Traversal ​

FunctionDescription
Foreach, ForeachWithError, ForeachNested, ForeachNestedWithErrorIterate arrays/objects (incl. deep traversal)
ForeachWithPath, ForeachWithPathAndIterator, ForeachWithPathAndControlIterate at a given path (carrying the current path / with break control)
ForeachReturnIterate and return the modified JSON
ForeachFile, ForeachFileWithPath, ForeachFileChunked, ForeachFileNestedItem-by-item file iteration (fully loaded, then item-by-item/batched callbacks)
NewIterator, NewBatchIterator, NewParallelIterator, NewStreamIteratorStandalone iterator constructors (see Iterators)

Cache and Globals ​

FunctionDescription
WarmupCache, ClearCacheCache warm-up / clearing
GetStats, GetHealthStatusRuntime statistics / health check
GetConfig, SetLoggerRead processor config / inject a logger (both global and Processor methods)
SetGlobalProcessor, ShutdownGlobalProcessorReplace and shut down the global processor
RegisterDangerousPattern, UnregisterDangerousPattern, ListDangerousPatternsGlobal dangerous-pattern registry register / remove / list (see Helper Functions)
CompilePath (Processor), PreParse (Processor)Path pre-compilation / JSON pre-parsing

Streaming ​

Type/MethodDescription
StreamLinesInto[T]Stream JSONL from a Reader and convert to []T
ParseJSONLParse JSONL bytes into []any
ToJSONL, ToJSONLStringConvert []any to JSONL format
JSONLWriterJSONL writer (Write/WriteAll/WriteRaw)
NDJSONProcessor (deprecated)NDJSON/JSONL processor (created by NewNDJSONProcessor; use the StreamJSONL family in new code)
ForeachFileItem-by-item file iteration (whole file loaded)

Validation ​

FunctionDescription
ValidJSON validation (encoding/json.Valid compatible)
ValidWithConfigJSON validation with config
ValidateSchemaSchema validation (used with the Schema type)
CompareJSONCompare JSON for equivalence
MergeJSON, MergeManyJSON merging (union/intersection/difference modes, see Helper Functions)

Naming Conventions ​

The library follows these naming conventions:

PatternDescriptionExample
Get{Type}Get as the given type (defaultValue supported)GetString, GetInt
GetTyped[T]Generic get, returns TGetTyped[User]
New{Type}Create an instanceNew (returns *Processor), NewEncoder
Default{Type}Default configurationDefaultConfig
{Type}ConfigConfiguration presetSecurityConfig, PrettyConfig
Foreach*Iteration variants (WithError / WithPath / Nested / File)ForeachNestedWithError
Stream*Streaming variants (Into / Parallel / File / Chunked)StreamJSONLParallel
{Verb}HookHook factoriesLoggingHook, ValidationHook

See Also ​