Documentation ¶
Overview ¶
Package badjson is a very bad json parser. It will take almost anything. It respects a notation to specify byte arrays by hex or base64. See parse_test.go and the readme. It will parse a lot of JSON and the output from `String()` resembles JSON but it's not really and the objects in key:value notation are just alternating fields in a list and there's no map here. 3/2020 Commented out all the number recognitions since we're not using it.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var B64DecodeMap [256]byte
B64DecodeMap from ascii to b64
var HexMap [256]byte
HexMap has values for hex
Functions ¶
func IsASCII ¶
IsASCII is true if all chars are >= ' ' and <= 127 the 2nd bool is if the string has delimeters so it would *need quotes*.
func MakeEscaped ¶
MakeEscaped will return an 'escaped' version of the string when string contains \ or " the usual escaping for json values and keys
func MakeUnescaped ¶
MakeUnescaped if we find a \ followed by a \ or a " then skip it
Types ¶
type Base64Bytes ¶
type Base64Bytes struct {
Base
}
Base64Bytes for when there's a block of data in base64
func (*Base64Bytes) GetBytes ¶
func (b *Base64Bytes) GetBytes() []byte
GetBytes try to parse b64 to bytes
func (*Base64Bytes) GetQuoted ¶
func (b *Base64Bytes) GetQuoted() string
func (*Base64Bytes) Raw ¶
func (b *Base64Bytes) Raw() string
Raw decodes and then reencodes because the input can be weird
type Parent ¶
type Parent struct { Base // contains filtered or unexported fields }
Parent has a sub-list
type RuneArray ¶
type RuneArray struct { Base // contains filtered or unexported fields }
RuneArray is a span of runes with quoting hints
type Segment ¶
type Segment interface { Next() Segment GetQuoted() string // as json so 123 or "abc" or "=ABC" or "$414243" Raw() string // unquoted // contains filtered or unexported methods }
Segment is a what a chunk of text will become and we'll be returning a list of them. Number or string or []byte are the only types.
func Chop ¶
Chop up a line of text into segments. Calling it a parser would be overstating. Returns a head of a list, the number of bytes consumed, and maybe an error.
Example ¶
package main import ( "fmt" "reflect" "github.com/awootton/knotfreeiot/badjson" ) func main() { someText := `abc:def,ghi:jkl` // an array of 4 strings // parse the text segment, err := badjson.Chop(someText) if err != nil { fmt.Println(err) } // traverse the result for s := segment; s != nil; s = s.Next() { fmt.Println(reflect.TypeOf(s)) } // output it output := badjson.ToString(segment) fmt.Println(output) someText = `"abc""def""ghi""jkl"` // an quoted array of 4 strings segment, err = badjson.Chop(someText) if err != nil { fmt.Println(err) } output = badjson.ToString(segment) fmt.Println(output) // Expect: *badjson.RuneArray // *badjson.RuneArray // *badjson.RuneArray // *badjson.RuneArray // ["abc","def","ghi","jkl"] // ["abc","def","ghi","jkl"] }
Output: