jsonedit

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPathExists             = errors.New("json path already exists")
	ErrAncestorDescendantPath = errors.New("cannot rename between ancestor and descendant paths")
)

JSON edit errors returned for invalid path operations.

Functions

This section is empty.

Types

type Document

type Document struct {
	Root   *Value
	Format Format
}

Document is an ordered JSON document plus the formatting preferences used to render it.

func NewObject

func NewObject(fallbackIndent int, sortKeys bool) *Document

NewObject creates an empty object document with fallback formatting.

func Parse

func Parse(data []byte, fallbackIndent int, sortKeys bool) (*Document, error)

Parse parses data into an ordered JSON document and detects its formatting.

func (*Document) Delete

func (d *Document) Delete(path []string) (bool, error)

Delete removes a nested value and prunes empty parent objects created by deletion.

func (*Document) Exists

func (d *Document) Exists(path []string) (bool, error)

Exists reports whether any JSON value exists at a nested path.

func (*Document) RenameString

func (d *Document) RenameString(from []string, to []string, overwrite bool) (bool, error)

RenameString moves a string value from one nested path to another.

func (*Document) Render

func (d *Document) Render() ([]byte, error)

Render serializes the document with its configured formatting.

func (*Document) SetString

func (d *Document) SetString(path []string, text string) error

SetString sets a nested string value, preserving existing object member order.

func (*Document) String

func (d *Document) String(path []string) (string, bool, error)

String returns the string value at a nested path.

type Format

type Format struct {
	Indent          string
	TrailingNewline bool
	SortKeys        bool
}

Format describes JSON rendering preferences.

func DetectFormat

func DetectFormat(data []byte, fallbackIndent int, sortKeys bool) Format

DetectFormat infers indentation and trailing newline style from JSON bytes.

type Kind

type Kind int

Kind identifies the JSON value representation stored in Value.

const (
	KindObject Kind = iota
	KindArray
	KindString
	KindRaw
)

Kind values identify object, array, string, and raw JSON representations.

type Member

type Member struct {
	Key   string
	Value *Value
}

Member is an object member in source order.

type RenderOptions

type RenderOptions struct {
	SortKeys bool
}

RenderOptions describes optional render overrides.

type Value

type Value struct {
	Kind    Kind
	Object  []Member
	Array   []*Value
	String  string
	RawJSON string
}

Value represents an ordered JSON value. Non-string scalar values are kept as raw JSON.

Jump to

Keyboard shortcuts

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