json

package
v0.0.0-...-baaee6e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Compare

type Compare struct{}

Compare provides comparison functionality for JSON values

func NewCompare

func NewCompare() *Compare

func (*Compare) Compare

func (c *Compare) Compare(a, b interface{}) (CompareResult, error)

Compare numerically compares two JSON values

func (*Compare) Equal

func (c *Compare) Equal(a, b interface{}) bool

Equal checks if two JSON values are equal

type CompareResult

type CompareResult int

CompareResult represents the result of a comparison operation

const (
	Less    CompareResult = -1
	Equal   CompareResult = 0
	Greater CompareResult = 1
)

type Merge

type Merge struct{}

Merge provides JSON merging functionality

func NewMerge

func NewMerge() *Merge

NewMerge creates a new instance of Merge

func (*Merge) DeepMerge

func (m *Merge) DeepMerge(target, source map[string]interface{}) map[string]interface{}

DeepMerge performs a deep merge of source into target

func (*Merge) DeepMergeWithOptions

func (m *Merge) DeepMergeWithOptions(target, source map[string]interface{}, opts *MergeOptions) map[string]interface{}

DeepMergeWithOptions performs a deep merge with custom options

func (*Merge) MergeMultiple

func (m *Merge) MergeMultiple(objects ...map[string]interface{}) map[string]interface{}

MergeMultiple merges multiple JSON objects together

func (*Merge) MergeMultipleWithOptions

func (m *Merge) MergeMultipleWithOptions(opts *MergeOptions, objects ...map[string]interface{}) map[string]interface{}

MergeMultipleWithOptions merges multiple JSON objects with custom options

func (*Merge) MergePatch

func (m *Merge) MergePatch(target, patch map[string]interface{}) map[string]interface{}

MergePatch applies a JSON merge patch according to RFC 7396

type MergeOptions

type MergeOptions struct {
	// OverwriteExisting determines if existing values should be overwritten
	OverwriteExisting bool
	// MaxDepth sets the maximum recursion depth for deep merge (-1 for unlimited)
	MaxDepth int
	// SkipNullValues determines if null values should be skipped during merge
	SkipNullValues bool
}

MergeOptions holds configuration for merge operations

func DefaultMergeOptions

func DefaultMergeOptions() *MergeOptions

DefaultMergeOptions returns default merge options

type PathUtil

type PathUtil struct{}

PathUtil provides path parsing and manipulation utilities for JSON operations

func NewPathUtil

func NewPathUtil() *PathUtil

NewPathUtil creates a new instance of PathUtil

func (*PathUtil) BuildPath

func (p *PathUtil) BuildPath(parts ...string) string

BuildPath constructs a path string from parts

func (*PathUtil) GetLastPart

func (p *PathUtil) GetLastPart(path string) string

GetLastPart returns the last component of the path

func (*PathUtil) GetParentPath

func (p *PathUtil) GetParentPath(path string) string

GetParentPath returns the parent path of the given path

func (*PathUtil) IsRoot

func (p *PathUtil) IsRoot(path string) bool

IsRoot checks if the given path is the root path

func (*PathUtil) ParseArrayIndex

func (p *PathUtil) ParseArrayIndex(part string) (int, bool)

ParseArrayIndex extracts the index from an array accessor Example: "[0]" -> 0, true Example: "name" -> 0, false

func (*PathUtil) ParsePath

func (p *PathUtil) ParsePath(path string) []string

ParsePath splits a JSON path into its component parts Example: "users.0.name" -> ["users", "0", "name"] Example: "users[0].name" -> ["users", "[0]", "name"]

func (*PathUtil) ResolvePath

func (p *PathUtil) ResolvePath(data interface{}, path string) (interface{}, error)

ResolvePath resolves a path against a JSON value and returns the target

func (*PathUtil) SetValueAtPath

func (p *PathUtil) SetValueAtPath(data map[string]interface{}, path string, value interface{}) error

SetValueAtPath sets a value at the specified path in a JSON object

func (*PathUtil) ValidatePath

func (p *PathUtil) ValidatePath(path string) error

ValidatePath checks if a path is syntactically valid

type RespUtil

type RespUtil struct{}

RespUtil provides utilities for converting between JSON and RESP format

func NewRespUtil

func NewRespUtil() *RespUtil

NewRespUtil creates a new instance of RespUtil

func (*RespUtil) JSONToRESP

func (r *RespUtil) JSONToRESP(value interface{}) models.Value

JSONToRESP converts a JSON value to RESP format

func (*RespUtil) RESPToJSON

func (r *RespUtil) RESPToJSON(value models.Value) interface{}

RESPToJSON converts a RESP value to JSON format

type Schema

type Schema struct {
	Type       SchemaType         `json:"type"`
	Properties map[string]*Schema `json:"properties,omitempty"`
	Required   []string           `json:"required,omitempty"`
	Items      *Schema            `json:"items,omitempty"`
	MinLength  *int               `json:"minLength,omitempty"`
	MaxLength  *int               `json:"maxLength,omitempty"`
	Minimum    *float64           `json:"minimum,omitempty"`
	Maximum    *float64           `json:"maximum,omitempty"`
	Pattern    *string            `json:"pattern,omitempty"`
	Enum       []interface{}      `json:"enum,omitempty"`
}

Schema represents a JSON schema structure

type SchemaType

type SchemaType string

SchemaType represents the type of a JSON value

const (
	TypeString  SchemaType = "string"
	TypeNumber  SchemaType = "number"
	TypeBoolean SchemaType = "boolean"
	TypeArray   SchemaType = "array"
	TypeObject  SchemaType = "object"
	TypeNull    SchemaType = "null"
)

type SearchOptions

type SearchOptions struct {
	CaseSensitive bool // Case-sensitive search
	IncludeKeys   bool // Search in keys
	IncludeValues bool // Search in values
}

SearchOptions contains configuration for search operations

func DefaultSearchOptions

func DefaultSearchOptions() *SearchOptions

DefaultSearchOptions returns default search options

type SearchResult

type SearchResult struct {
	Path  string      // Path where the match was found
	Key   string      // Key that matched
	Value interface{} // Value that matched
	IsKey bool        // Indicates if the match was in a key
}

SearchResult represents a search match

type SearchUtil

type SearchUtil struct{}

SearchUtil provides JSON search functionality

func NewSearchUtil

func NewSearchUtil() *SearchUtil

NewSearchUtil creates a new instance of SearchUtil

func (*SearchUtil) Search

func (s *SearchUtil) Search(jsonData, keyword string, opts *SearchOptions) []SearchResult

type ValidationError

type ValidationError struct {
	Path    string
	Message string
}

ValidationError represents a schema validation error

func (*ValidationError) Error

func (e *ValidationError) Error() string

type ValidationUtil

type ValidationUtil struct{}

ValidationUtil provides JSON schema validation functionality

func NewValidationUtil

func NewValidationUtil() *ValidationUtil

NewValidationUtil creates a new instance of ValidationUtil

func (*ValidationUtil) Validate

func (v *ValidationUtil) Validate(value interface{}, schema *Schema) error

Validate validates a JSON value against a schema

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL