jsonparser is a Go library for reading JSON data quickly, without needing to define the shape of the data in advance. Go's built-in JSON package requires you to write out a struct that matches the structure of the JSON you plan to receive. If the data comes from a third-party API and its structure is unpredictable or changes over time, that approach gets awkward. jsonparser lets you pull out individual fields by specifying a path, more like looking something up in a nested dictionary than mapping the whole thing to a type. The library's main selling point is speed. According to the benchmarks in the README, it can be up to ten times faster than Go's standard encoding/json package, and it avoids memory allocation during parsing. That makes it useful in high-throughput situations where you are processing a large number of JSON responses and do not want garbage collection pressure from repeated allocations. The API centers on a Get function that takes the raw JSON bytes and a sequence of keys that form a path into the document. For example, to read a nested field you pass the outer key first, then the inner key, and the function returns the value as a byte slice along with its type. There are helper functions for common types: GetString, GetInt, GetFloat, and GetBoolean. Arrays can be iterated with ArrayEach, which calls a function for each element. ObjectEach does the same for key-value pairs in an object. For cases where you need to read several different fields from the same document, an EachKey function scans the payload only once and calls your callback each time it finds one of the paths you listed. This is more efficient than calling Get multiple times, since each Get call reads through the data independently. The library also includes a Set function for writing or updating values in existing JSON bytes. The README includes extensive code examples and benchmark comparisons against other Go JSON libraries.
← buger on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.