Skip to content

API Reference

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

Two API Styles

This library offers package-level functions (e.g., json.GetString(data, "path"), no instance needed) and Processor methods (e.g., p.GetString(data, "path"), with config reuse, pre-parse caching, and hooks). 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/iterate)
ProcessorProcessor methods (mirrors package functions by category, plus lifecycle and pre-parse)

Types & Interfaces

ModuleDescription
ConfigConfiguration options in detail (DefaultConfig / SecurityConfig / PrettyConfig)
Type DefinitionsCore types (Config / Schema / Stats / AccessResult, including Encoder / Decoder)
Interface DefinitionsExtension interfaces (CustomEncoder / Validator / Hook / PathParser)
Iterators & IterableValueIterator / BatchIterator / ParallelIterator / StreamIterator types
Generic OperationsGeneric API (GetTyped[T] / StreamLinesInto[T] / Result[T])
Constants & ErrorsConstants and error types

Utilities

ModuleDescription
Utility FunctionsCompareJSON / MergeJSON, cache management, global processor, SafeError / RedactedPath, AccessResult methods
Formatting GuidePrint series migration guide (alternatives for removed APIs)

Cross-cutting Topics

ModuleDescription
Stream ProcessingLarge file stream processing guide
NDJSON ProcessingJSONL processor (StreamJSONL / NDJSONProcessor / JSONLWriter)
SecuritySecurity mode API (SecurityConfig / DangerousPattern / RegisterDangerousPattern)
ValidatorSchema validation (ValidateSchema / DefaultSchema / NewSchemaWithConfig)
Hook SystemOperation interception hooks (LoggingHook / TimingHook / ValidationHook / ErrorHook)
Custom EncoderCustom encoders (CustomEncoder / TypeEncoder)

Quick Find

By Feature Category

Path Queries

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

Modify Operations

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

Encoding & Decoding

FunctionDescription
Marshal, UnmarshalStandard encoding/decoding (compatible with encoding/json, optional cfg)
MarshalIndentPretty-print encoding (compatible with encoding/json.MarshalIndent, optional cfg)
Encode, EncodeWithConfigEncode to string
NewEncoder, NewDecoderStream encoding/decoding
ParseParse JSON

Formatting

FunctionDescription
PrettifyFormat JSON
CompactCompact JSON (buffer form, compatible with encoding/json.Compact)
CompactStringCompact JSON (string in/out form, mirrors Processor.Compact)

File Operations

FunctionDescription
LoadFromFile, SaveToFileFile read/write
LoadFromReaderRead from Reader
MarshalToFile, UnmarshalFromFileFile encoding/decoding

Stream Processing

Type/MethodDescription
StreamLinesInto[T]Stream read JSONL from Reader and convert to []T
ParseJSONLParse JSONL bytes to []any
ToJSONL, ToJSONLStringConvert []any to JSONL format
JSONLWriterJSONL writer (Write/WriteAll/WriteRaw)
NDJSONProcessorNDJSON/JSONL processor
ForeachFileFile stream processing

Validation

FunctionDescription
ValidJSON validation (compatible with encoding/json.Valid)
ValidWithConfigJSON validation with configuration
ValidateSchemaSchema validation (used with Schema type)
CompareJSONCompare JSON for equivalence

Naming Conventions

The library follows these naming conventions:

PatternDescriptionExample
Get{Type}Get specified type (supports defaultValue)GetString, GetInt
GetTyped[T]Generic getter, returns TGetTyped[User]
New{Type}Create instanceNew (returns *Processor), NewEncoder
Default{Type}Default configurationDefaultConfig
{Type}ConfigConfiguration presetSecurityConfig, PrettyConfig