json

package module
v0.86.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 5 Imported by: 3 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package json implements helper functions to interact with json

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetNestedValue

func GetNestedValue(inputMap map[string]interface{}, keys ...string) interface{}

GetNestedValue returns the value in the map specified by the array keys, where each value is another depth level in the map. Returns nil if the map doesn't contain the nested key.

func PrintJSON added in v0.77.0

func PrintJSON(w io.Writer, rawJSON any, prettyPrintJSON bool, removeEmpty bool, searchTerm string) error

PrintJSON writes JSON output to the provided writer, optionally pretty-printed.

Types

type EmptyPolicy

type EmptyPolicy int

EmptyPolicy defines the behavior when adding an empty string

const (
	// OmitEmpty does not write the field if the string is empty
	OmitEmpty EmptyPolicy = iota

	// AllowEmpty writes the string even if the string is empty
	AllowEmpty
)

type RawObjectWriter

type RawObjectWriter struct {
	// contains filtered or unexported fields
}

RawObjectWriter contains helper functions to write JSON using the raw API.

func NewRawObjectWriter

func NewRawObjectWriter(stream *jsoniter.Stream) *RawObjectWriter

NewRawObjectWriter creates a new instance of RawObjectWriter

func (*RawObjectWriter) AddInt64Field

func (writer *RawObjectWriter) AddInt64Field(fieldName string, value int64)

AddInt64Field adds a new field of type int64

func (*RawObjectWriter) AddStringField

func (writer *RawObjectWriter) AddStringField(fieldName string, value string, policy EmptyPolicy)

AddStringField adds a new field of type string

func (*RawObjectWriter) AddStringValue

func (writer *RawObjectWriter) AddStringValue(value string)

AddStringValue adds a string (for example inside an array)

func (*RawObjectWriter) FinishArrayField

func (writer *RawObjectWriter) FinishArrayField() error

FinishArrayField finishes an array field

func (*RawObjectWriter) FinishObject

func (writer *RawObjectWriter) FinishObject() error

FinishObject finishes a JSON object (add '}')

func (*RawObjectWriter) Flush

func (writer *RawObjectWriter) Flush() error

Flush the stream

func (*RawObjectWriter) StartArrayField

func (writer *RawObjectWriter) StartArrayField(fieldName string) error

StartArrayField starts a new field of type array

func (*RawObjectWriter) StartObject

func (writer *RawObjectWriter) StartObject() error

StartObject starts a new JSON object (add '{')

Jump to

Keyboard shortcuts

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