jsonx

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 10 Imported by: ? modules, 0 packages

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 jsonx reads and writes JSON as Python's json module does, which the files training and evaluation tools read are written in: an object keeps the order of its keys, a number the text it was written with, and a value is laid out as json.dumps lays it out, with a space after each comma and colon and the text of strings left as it is

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(data []byte) (any, error)

Value of the JSON text: an *Object, a []any, a string, a json.Number, a bool or nil, objects keeping the order of their keys

func Encode

func Encode(v any) ([]byte, error)

One line of JSON as json.dumps writes it with ensure_ascii off: a space after each comma and colon, text left as it is

func Float

func Float(v any) (float64, bool)

Number a value holds, false for a value that is none

func Indent

func Indent(v any, ascii bool) ([]byte, error)

JSON as json.dump writes it with an indent of two: each item on its own line, every character past ASCII escaped when ascii is set

func Int

func Int(v any) (int64, bool)

Whole number a value holds, false for a value that is none or has a fraction

func Text

func Text(v any) string

Text of a value as Python's str writes it of the values JSON holds: text as it is, anything else as its repr

func Truthy

func Truthy(v any) bool

Whether a value counts as true as Python tests it: false for nil, false, zero, empty text and empty lists and objects

Types

type Object

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

Object of JSON whose keys keep the order they were set in, the first setting of a key giving its place

func NewObject

func NewObject(pairs ...any) *Object

Object of the keys and values given in turn, each key a string

func (*Object) Clone

func (o *Object) Clone() *Object

Copy of the object holding the same values in the same order

func (*Object) Delete

func (o *Object) Delete(key string)

Removes the key and its value

func (*Object) Get

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

Value of the key, and whether the object has it

func (*Object) Keys

func (o *Object) Keys() []string

Keys in their order

func (*Object) Len

func (o *Object) Len() int

func (*Object) MarshalJSON

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

The object as one line of JSON in its order, for code that writes it through encoding/json

func (*Object) Set

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

Sets the key to the value, the key kept in its place when it was set before and put last when it is new

func (*Object) Value

func (o *Object) Value(key string) any

Value of the key, nil when the object has none

Jump to

Keyboard shortcuts

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