Awesome Go

jseq

CategoryJSON
SubcategoryJSON
Stars0

Streaming JSON parser

About jseq

Jseq - streaming JSON parser

Go Reference Tests Coverage Status

This is jseq, a streaming JSON parser.

The main function in this package, Values, produces JSON values from its input as soon as they are encountered. This means that interior values − those nested inside a JSON object or array − are produced first, before the surrounding structure is complete.

Each value produced by Values is paired with an RFC 6901-style JSON “pointer” that can locate it within its top-level object.

For a concrete example, consider this JSON input:

{"hello": [1, 2], "world": [3, 4]}

Given this input, Values produces pointer/value pairs in this order:

PointerValue
"/hello/0"1
"/hello/1"2
"/hello"[1, 2]
"/world/0"3
"/world/14
"/world"[3, 4]
""{"hello": [1, 2], "world": [3, 4]}

For more information, see the Go doc for this package.

Usage

If r is the source of some JSON-encoded data, then typical usage looks like this:

tokens, errptr1 := jseq.Tokens(r)
pairs, errptr2 := jseq.Values(tokens)

for pointer, value := range pairs {
  // Handle a value.
  // Note that you can use len(pointer)==0
  // to detect when you’ve parsed a complete top-level object.
  // (More generally, len(pointer) tells you the nesting depth of the value.)
}
if err := *errptr1; err != nil {
  // Handle error from jseq.Tokens
}
if err := *errptr2; err != nil {
  // Handle error from jseq.Values
}

Frequently Asked Questions

What is jseq?

jseq is a JSON library for the Go programming language. Streaming JSON parser

How do I install jseq?

Install jseq with the Go module system using `go get bobg/jseq`. Check the repository for the current installation instructions.

What category does jseq belong to?

jseq is listed under JSON, specifically JSON.

← Back to JSON