pyjson

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 23 Imported by: 0 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

Index

Constants

This section is empty.

Variables

View Source
var ErrCircular = errors.New("Circular reference detected")

ValueError json.dumps raises when check_circular finds a container inside itself

View Source
var ErrOutOfRange = errors.New("Out of range float values are not JSON compliant")

ValueError json.dumps raises for a NaN or infinite float when allow_nan is false

View Source
var ErrRecursion = errors.New("maximum recursion depth exceeded while encoding a JSON object")

RecursionError for a default hook that keeps returning values needing default past the interpreter limit

Functions

func AppendStringWTF8

func AppendStringWTF8(dst []byte, src string) []byte

Quoted JSON string of WTF-8 text, surrogates kept as their code points and stray bytes as surrogateescape chars

func Clone

func Clone(v any) any

Deep copy keeping every Object ordered, copying maps, lists and values that rebuild themselves

func DecodeBytes

func DecodeBytes(b []byte) (string, error)

Text of bytes under json.detect_encoding, decoded with surrogatepass, the UnicodeDecodeError on bad input

func DecodeWTF8

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

Decodes JSON into the encoding/json any shapes with lone surrogate escapes kept as WTF-8 code points

func DecodeWTF8Numbers

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

Decodes JSON into plain maps with numbers as json.Number text so ints stay apart from floats

func DecodeWTF8Ordered

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

Decodes JSON with objects as insertion ordered dicts and numbers as json.Number text

func Dict

func Dict(v any) (map[string]any, bool)

Read view of a dict value, a plain map itself or the value map of an Object, false for anything else

func Dumps

func Dumps(v any, opts ...Option) (string, error)

json.dumps of v under the given keyword arguments, Python defaults for the rest

func EncodeWTF8

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

Encodes like json.dumps with ensure_ascii false, encoding/json value shapes without HTML escaping and surrogates as code points

func EncodeWTF8Indent

func EncodeWTF8Indent(v any, prefix, indent string) ([]byte, error)

Indented form of EncodeWTF8 with the encoding/json Encoder indent layout

func EncodeWTF8Python

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

Text of json.dumps with ensure_ascii false and the default comma space and colon space separators

func EncodeWTF8PythonASCII

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

Text of json.dumps with every default, characters outside space to tilde escaped and separators spaced

func Equal

func Equal(a, b any) bool

Python equality of decoded JSON values, dicts ignoring key order and numbers comparing across int, float and bool

func EscapeNonASCII

func EscapeNonASCII(out []byte) []byte

Rewrites each non ASCII character of encoded JSON as backslash u escapes, astral ones as a surrogate pair

func Loads

func Loads(text string) (any, error)

json.loads of text into ordered objects, int64 or big.Int ints, float64 floats and WTF-8 strings

func LoadsBytes

func LoadsBytes(b []byte) (any, error)

json.loads of bytes, decoded under json.detect_encoding with surrogatepass first

func LoadsBytesPairsHook

func LoadsBytesPairsHook(b []byte, hook func(keys []string, vals []any) (any, error)) (any, error)

json.loads of bytes under json.detect_encoding with object_pairs_hook

func LoadsLenient

func LoadsLenient(text string) (any, error)

json.loads with strict=False, control characters accepted raw inside strings

func LoadsOrdered

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

JSON value with objects as Object in wire key order and numbers kept as json.Number text

func LoadsPairsHook

func LoadsPairsHook(text string, hook func(keys []string, vals []any) (any, error)) (any, error)

json.loads with object_pairs_hook, each object built by hook from its keys and values in order

func LoadsPartial

func LoadsPartial(text string) (any, error)

Plain value of a JSON prefix like jiter partial mode, open containers closed and incomplete strings and literals dropped

func Ordered

func Ordered(v any) any

Value with every string keyed dict at any depth turned into an Object, plain map keys sorted

func ParseInt

func ParseInt(text string) any

Python int of decimal JSON integer text, int64 when it fits and big.Int beyond

func Plain

func Plain(v any) any

Decoded JSON with every Object turned into a plain map and every map and list copied, scalars unchanged

func RawDecode

func RawDecode(text string) (any, int, error)

json.JSONDecoder().raw_decode of text from its first character, the value and the rune offset after it

func SafeLoads

func SafeLoads(v any, def any) any

utils.safe_json_loads, json.loads of a str or bytes value with def returned for any decode error or non text argument

func SpaceSeparators

func SpaceSeparators(compact []byte) []byte

Adds the space json.dumps writes after each item comma and key colon of compact JSON text

func WTF8Shape

func WTF8Shape(v any) any

Python decoded value in the DecodeWTF8 shapes, dicts as plain maps and every int or float as float64

Types

type DecodeError

type DecodeError struct {
	Msg                string
	Pos, Lineno, Colno int
}

JSON decode error formatted with line, column and character offset like json.JSONDecodeError

func (*DecodeError) Error

func (e *DecodeError) Error() string

func (*DecodeError) PyTypeName

func (e *DecodeError) PyTypeName() string

type Object

type Object struct {
	Keys []string
	Vals map[string]any
}

Insertion ordered JSON object with dict semantics, a reassigned key keeping its first position

func AsObject

func AsObject(v any) (*Object, bool)

Object view of a dict value, a plain map entering with sorted keys, false for anything else

func LoadsDict

func LoadsDict(text string) (*Object, error)

Decoded JSON object of text, the AttributeError a dict get call raises on any other decoded value

func NewObject

func NewObject() *Object

Empty ordered object ready for Set

func ObjectOf

func ObjectOf(pairs ...any) *Object

Ordered object built from alternating string keys and values in dict literal order

func (*Object) Copy

func (o *Object) Copy() *Object

Shallow copy with the same key order, the dict.copy analogue

func (*Object) Delete

func (o *Object) Delete(key string) bool

Removes key and its position, reporting whether it was present

func (*Object) Get

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

Value stored under key and whether the key exists

func (*Object) GetOr

func (o *Object) GetOr(key string, def any) any

Value of key, def when the key is absent as dict get with a default returns

func (*Object) Len

func (o *Object) Len() int

Number of keys

func (*Object) MarshalJSON

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

Writes keys in insertion order with encoding/json compact spacing and surrogates kept as code points

func (*Object) Pop

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

Removes key and returns its value and whether it was present, the dict.pop analogue

func (*Object) PyItems

func (o *Object) PyItems() iter.Seq2[any, any]

Keys and values in insertion order so the object renders as a Python dict

func (*Object) Set

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

Stores v under key, appending the key only on first insertion

func (*Object) UnmarshalJSON

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

Decodes a JSON object the way json.loads does, keys kept in document order

func (*Object) Update

func (o *Object) Update(other *Object)

Sets every key of other in its order, existing keys keeping their position as dict.update does

type Option

type Option func(*options)

One json.dumps keyword argument

func AllowNaN

func AllowNaN(on bool) Option

allow_nan, true by default

func Default

func Default(fn func(any) (any, error)) Option

default, called for values json cannot encode and its result encoded in their place

func EnsureASCII

func EnsureASCII(on bool) Option

ensure_ascii, true by default

func Indent

func Indent(n int) Option

indent given as a count of spaces, zero meaning newlines with no indentation

func Separators

func Separators(item, key string) Option

separators as the item and key separator pair

func SortKeys

func SortKeys(on bool) Option

sort_keys

type TypeError

type TypeError struct{ Msg string }

TypeError json.dumps raises for a value neither encodable nor converted by default

func (*TypeError) Error

func (e *TypeError) Error() string

func (*TypeError) PyTypeName

func (e *TypeError) PyTypeName() string

Python exception class name the error stands for

Jump to

Keyboard shortcuts

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