8000 GitHub - iOliverNguyen/ujson at v1.0.0
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

µjson - A fast and minimal JSON parser and transformer that works on unstructured JSON

License

Notifications You must be signed in to change notification settings

iOliverNguyen/ujson

Repository files navigation

µjson

Build Status GoDoc License

A fast and minimal JSON parser and transformer that works on unstructured json. Example use cases:

  1. Walk through unstructured json:
  2. Transform unstructured json:

without fully unmarshalling it into a map[string]interface{}.

See usage and examples on godoc.org.

CAUTION: Behaviour is undefined on invalid json. Use on trusted input only.

Usage

The single most important function is Walk(input, callback), which parses the input json and call callback function for each key/value pair processed.

Let's see an example:

{
    "id": 12345,
    "name": "foo",
    "numbers": ["one", "two"],
    "tags": {"color": "red", "priority": "high"},
    "active": true
}

Calling Walk() with the above input will produce:

indent key value
0 {
1 "id" 12345
1 "name" "foo"
1 "numbers" [
2 "one"
2 "two"
1 ]
1 "tags" {
2 "color" "red"
2 "priority" "high"
1 }
1 "active" true
0 }

indent indicates the indentation of the key/value pair as if the json is formatted properly. keys and values are provided as raw literal. Strings are always double-quoted. To get the original string, use Unquote().

value will never be empty (for valid json). You can test the first byte (value[0]) to get its type:

  • n: Null (null)
  • f, t: Boolean (false, true)
  • 0-9: Number
  • ": String, see Unquote()
  • [, ]: Array
  • {, }: Object

When processing arrays and objects, first the open bracket ([, {) will be provided as value, followed by its children, and finally the close bracket (], }). When encounting open brackets, You can make the callback function return false to skip the array/object entirely.

About

µjson - A fast and minimal JSON parser and transformer that works on unstructured JSON

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0