jsn

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2019 License: MIT Imports: 9 Imported by: 0

README

JSN - Fast low allocation JSON library

Design

This libary is designed as a set of seperate functions to extract data and mutate JSON. All functions are focused on keeping allocations to a minimum and be as fast as possible. The functions don't validate the JSON a seperate Validate function does that.

The JSON parsing algo processes each object {} or array [] in a bottom up way where once the end of the array or object is found only then the keys within it are parsed from the top down.

{"id":1,"posts": [{"title":"PT1-1","description":"PD1-1"}], "full_name":"FN1","email":"E1" }

id: 1

posts: [{"title":"PT1-1","description":"PD1-1"}]

[{"title":"PT1-1","description":"PD1-1"}]

{"title":"PT1-1","description":"PD1-1"}

title: "PT1-1"

description: "PD1-1

full_name: "FN1"

email: "E1"

Functions

  • Strip: Strip a path from the root to a child node and return the rest
  • Replace: Replace values by key
  • Get: Get all keys
  • Filter: Extract specific keys from an object
  • Tree: Fetch unique keys from an array or object

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

func Filter(w *bytes.Buffer, b []byte, keys []string) error

func Keys

func Keys(b []byte) [][]byte

func Replace

func Replace(w *bytes.Buffer, b []byte, from, to []Field) error

func Strip

func Strip(b []byte, path [][]byte) []byte

func Tree

func Tree(v []byte) (map[string]interface{}, bool, error)

func Validate

func Validate(s string) error

Validate validates JSON s.

func ValidateBytes

func ValidateBytes(b []byte) error

ValidateBytes validates JSON b.

func Value

func Value(b []byte) []byte

Types

type Field

type Field struct {
	Key   []byte
	Value []byte
}

func Get

func Get(b []byte, keys [][]byte) []Field

type Stack

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

func NewStack

func NewStack() *Stack

Create a new Stack

func (*Stack) Len

func (s *Stack) Len() int

Return the number of items in the Stack

func (*Stack) Peek

func (s *Stack) Peek() *skipInfo

View the top item on the Stack

func (*Stack) Pop

func (s *Stack) Pop() *skipInfo

Pop the top item of the Stack and return it

func (*Stack) Push

func (s *Stack) Push(value skipInfo)

Push a value onto the top of the Stack

Jump to

Keyboard shortcuts

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