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 ¶
- func JArray() parser.Parser[Json]
- func JBool() parser.Parser[Json]
- func JFloat() parser.Parser[Json]
- func JInt() parser.Parser[Json]
- func JNull() parser.Parser[Json]
- func JObject() parser.Parser[Json]
- func JPair() parser.Parser[JsonPair]
- func JString() parser.Parser[Json]
- func JVal() parser.Parser[Json]
- func ParseJSON(jsonStr string) parser.ParserFuncRet[Json]
- type Json
- type JsonArray
- type JsonBool
- type JsonFloat
- type JsonInt
- type JsonNull
- type JsonObject
- type JsonPair
- type JsonString
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JArray ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
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 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.