Skip to content
bobgPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

15 Commits

Folders and files

Repository files navigation

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:

Pointer Value
"/hello/0" 1
"/hello/1" 2
"/hello" [1, 2]
"/world/0" 3
"/world/1 4
"/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
}

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages