json

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package json defines a set of types to represent JSON data in Go.

Package json provides a set of parsers for JSON data using the tiny-parsec library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JArray

func JArray() parser.Parser[Json]

JArray parses a JSON array value and returns a JsonArray object. It uses the Between combinator to parse the array enclosed in square brackets, and the SepBy combinator to parse the elements separated by commas.

func JBool

func JBool() parser.Parser[Json]

JBool parses a JSON boolean value (true or false) and returns a JsonBool object. It uses the OrElse combinator to try parsing "true" or "false", and then the Fmap combinator to transform the result.

func JFloat

func JFloat() parser.Parser[Json]

JFloat parses a JSON floating-point value and returns a JsonFloat object. It uses the Trim combinator to remove leading and trailing whitespace, and the Fmap combinator to transform the parsed float.

func JInt

func JInt() parser.Parser[Json]

JInt parses a JSON integer value and returns a JsonInt object. It uses the Trim combinator to remove leading and trailing whitespace, and the Fmap combinator to transform the parsed integer.

func JNull

func JNull() parser.Parser[Json]

JNull parses the JSON null value and returns a JsonNull object. It uses the Fmap combinator to transform the parsed string "null" into a JsonNull object.

func JObject

func JObject() parser.Parser[Json]

JObject parses a JSON object value and returns a JsonObject object. It uses the Between combinator to parse the object enclosed in curly braces, and the SepBy combinator to parse the key-value pairs separated by commas.

func JPair

func JPair() parser.Parser[JsonPair]

JPair parses a JSON key-value pair and returns a JsonPair object. It uses the Seq combinator to parse the key (a string), the colon separator, and the value, and then the Fmap combinator to transform the result.

func JString

func JString() parser.Parser[Json]

JString parses a JSON string value and returns a JsonString object. It uses the Trim combinator to remove leading and trailing whitespace, and the Fmap combinator to transform the parsed string.

func JVal

func JVal() parser.Parser[Json]

JVal parses a JSON value, which can be a string, number, boolean, null, array, or object. It uses the OrElse combinator to try different parsers in order until one succeeds.

func ParseJSON

func ParseJSON(jsonStr string) parser.ParserFuncRet[Json]

Types

type Json

type Json interface {
	// contains filtered or unexported methods
}

Json is an interface that all JSON types must implement. It includes a method to indicate the type of the JSON value.

type JsonArray

type JsonArray struct {
	// Val is the slice of Json values that make up the JSON array.
	Val []Json
}

JsonArray represents a JSON array value.

type JsonBool

type JsonBool struct {
	// Val is the boolean value of the JSON boolean.
	Val bool
}

JsonBool represents a JSON boolean value.

type JsonFloat

type JsonFloat struct {
	// Val is the floating-point value of the JSON float.
	Val float64
}

JsonFloat represents a JSON floating-point value.

type JsonInt

type JsonInt struct {
	// Val is the integer value of the JSON integer.
	Val int64
}

JsonInt represents a JSON integer value.

type JsonNull

type JsonNull struct{}

JsonNull represents a JSON null value.

func (JsonNull) IsNil

func (j JsonNull) IsNil() bool

IsNil returns true if the JsonNull value is nil.

type JsonObject

type JsonObject struct {
	// Val is the map of string keys to Json values that make up the JSON object.
	Val map[string]Json
}

JsonObject represents a JSON object value.

type JsonPair

type JsonPair struct {
	// Key is the string key of the JSON pair.
	Key string
	// Value is the Json value of the JSON pair.
	Value Json
}

JsonPair represents a key-value pair in a JSON object.

type JsonString

type JsonString struct {
	// Val is the string value of the JSON string.
	Val string
}

JsonString represents a JSON string value.

Jump to

Keyboard shortcuts

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