json

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package json provides a JSON format handler for chezmoi-split.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StripComments

func StripComments(data []byte) []byte

StripComments removes single-line // comments from JSON. This allows parsing JSONC (JSON with comments) files.

Types

type Handler

type Handler struct{}

Handler implements format.Handler for JSON/JSONC files.

func New

func New() *Handler

New creates a new JSON handler.

func (*Handler) GetPath

func (h *Handler) GetPath(tree any, p path.Path) (any, bool)

GetPath extracts a value at the given path, supporting wildcards.

func (*Handler) Parse

func (h *Handler) Parse(data []byte, opts format.ParseOptions) (any, error)

Parse reads JSON bytes and returns an *orderedmap.OrderedMap. All nested objects are also converted to OrderedMaps to preserve key order.

func (*Handler) Serialize

func (h *Handler) Serialize(tree any, opts format.SerializeOptions) ([]byte, error)

Serialize writes the tree to formatted JSON bytes.

func (*Handler) SetPath

func (h *Handler) SetPath(tree any, p path.Path, value any) error

SetPath sets a value at the given path, supporting wildcards. Creates intermediate maps as needed.

Jump to

Keyboard shortcuts

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