fieldpath

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package fieldpath reads nested values out of a decoded JSON object (map[string]any) by path. The default syntax is a dot-separated path, like "user.id". A path that begins with "/" is instead an RFC 6901 JSON Pointer ("/user/id"), which can address a key that itself contains a dot ("/http.status"). It is the lookup the field-matching rules build on.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(fields map[string]any, path string) (any, bool)

Get is Lookup for a path that has not been split yet. An empty path returns (nil, false).

func Lookup

func Lookup(fields map[string]any, segments []string) (any, bool)

Lookup walks fields by precompiled segments and returns the value at the end and whether it was found. A segment that is missing, or that tries to descend into something that is not an object, returns (nil, false), as does an empty path. A path may end on any value, including a nested object or an array; descending into an array (numeric indexing) is not supported.

func Split

func Split(path string) []string

Split breaks a path into segments. A "/"-prefixed path is parsed as a JSON Pointer (see splitPointer); otherwise it is split on ".". An empty path returns nil so it round-trips through Lookup the same way Get treats "". Callers on a hot path should Split once and reuse the result with Lookup rather than calling Get per record.

Types

This section is empty.

Jump to

Keyboard shortcuts

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