ojson

package module
v0.0.0-...-8e9f4e3 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2025 License: MIT Imports: 3 Imported by: 0

README

Description

The ojson package provides several data types that can be used to encode and decode JSON while preserving object keys order. The name ojson stands for "Ordered JSON".

Documentation

You can find the documentation of the package here

Documentation

Overview

Package ojson provides several data types that can be used to encode and decode JSON while preserving object keys order. The name "ojson" stands for "Ordered JSON".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Any

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

Any represents any Go value. When using it to decode a JSON value it ensures that embedded JSON objects are decoded as Object.

func (Any) MarshalJSON

func (a Any) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Any) UnmarshalJSON

func (a *Any) UnmarshalJSON(d []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (Any) Value

func (a Any) Value() any

Value returns the value encapsulated in a.

type Array

type Array []any

Array represents a slice of any values. When using it to decode a JSON array it ensures that embedded JSON objects are decoded as Object.

func (*Array) UnmarshalJSON

func (a *Array) UnmarshalJSON(d []byte) error

MarshalJSON implements the json.Marshaler interface.

type Object

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

Object represents a JSON object. It is the equivalent of map[string]any but when used to decode/encode a JSON object it preserves the object keys order. It can also be used as an ordered map.

func NewObject

func NewObject() *Object

NewObject creates a new Object ready to be used.

func (*Object) Clear

func (o *Object) Clear()

Clear deletes all entries in the object, resulting in an empty object.

func (*Object) Delete

func (o *Object) Delete(key string)

Delete deletes the value for a key.

func (*Object) Get

func (o *Object) Get(key string) (v any, ok bool)

Get returns the value stored in the object for a key, or nil if no value is present. The ok result indicates whether value was found in the object.

func (*Object) Len

func (o *Object) Len() int

Len returns the number of elements in the object.

func (*Object) MarshalJSON

func (o *Object) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Object) Range

func (o *Object) Range(f func(key string, value any) bool)

Range calls f sequentially for each key and value present in the object. If f returns false, range stops the iteration.

func (*Object) Set

func (o *Object) Set(key string, value any)

Set sets the value for a key

func (*Object) UnmarshalJSON

func (o *Object) UnmarshalJSON(d []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

Jump to

Keyboard shortcuts

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