import ( "github.com/mailru/easyjson/jlexer" "fmt" ) func parseArray(data []byte) { // Create a new lexer instance l := jlexer.Lexer{Data: data} // Begin scanning for array elements l.Delim('[') for !l.IsDelim(']') { // Parse the next array element val := l.String() // Print the parsed value fmt.Println(val) } l.Delim(']') }
import ( "github.com/mailru/easyjson/jlexer" "fmt" ) func parseObject(data []byte) { // Create a new lexer instance l := jlexer.Lexer{Data: data} // Begin scanning for object key/value pairs l.Delim('{') for !l.IsDelim('}') { // Parse the next object key key := l.String() // Advance to the next token l.WantColon() // Parse the corresponding value val := l.String() // Print the parsed key/value pair fmt.Printf("%s: %s\n", key, val) } l.Delim('}') }In this example, we use the `WantColon()` method to advance to the next token after parsing an object key. We then parse the corresponding value and print out the resulting key/value pair. Overall, the jlexer package is a powerful tool for efficiently parsing JSON data in Go applications. Its support for delimiter-based parsing makes it a particularly effective choice for working with large JSON datasets.