dynjson alternatives and similar packages
Based on the "JSON" category.
Alternatively, view dynjson alternatives based on common mentions on social networks and blogs.
-
jsonparser
One of the fastest alternative JSON parser for Go that does not require schema -
fastjson
Fast JSON parser and validator for Go. No custom structs, no code generation, no reflection -
jsondiff
Compute the diff between two JSON documents as a series of RFC6902 (JSON Patch) operations -
marshmallow
Marshmallow provides a flexible and performant JSON unmarshalling in Go. It specializes in dealing with unstructured struct - when some fields are known and some aren't, with zero performance overhead nor extra coding needed. -
JSON-to-Proto
convert JSON to Protocol Buffers online in your browser instantly -
ujson
µjson - A fast and minimal JSON parser and transformer that works on unstructured JSON -
ask
A Go package that provides a simple way of accessing nested properties in maps and slices. -
mapslice-json
Go MapSlice for ordered marshal/ unmarshal of maps in JSON -
go-jsonerror
Small package which wraps error responses to follow jsonapi.org -
epoch
Contains primitives for marshaling/unmarshaling Unix timestamp/epoch to/from built-in time.Time type in JSON -
Better Parsing of Unstructured JSON in Go
An error propagating JSON parsing library for Go -
omg.jsonparser
The simple JSON parser with validation by condition -
go-parameters
:blue_book: Easily parse incoming parameters and values from an HTTP request -
jsonhandlers
JSON library to expose simple handlers that lets you easily read and write json from various sources.
WorkOS - The modern identity platform for B2B SaaS
Do you think we are missing an alternative of dynjson or a related project?
Popular Comparisons
README
dynjson
Client-customizable JSON formats for dynamic APIs.
Introduction
dynjson allow APIs to return only fields selected by the API client:
GET https://api.example.com/v1/foos
[{"id":1,foo":1,"bar":2,"baz":3}]
GET https://api.example.com/v1/foos?select=foo
[{"foo":1}]
GET https://api.example.com/v1/foos/1?select=foo
{"foo":1}
dynjson mimicks the original struct using the original types and json tags. The field order is the same as the select parameters.
Installation
go get github.com/cocoonspace/dynjson
Examples
type APIResult struct {
Foo int `json:"foo"`
Bar string `json:"bar"`
}
f := dynjson.NewFormatter()
res := &APIResult{Foo:1, Bar:"bar"}
o, err := f.Format(res, dynjson.FieldsFromRequest(r))
if err != nil {
// handle error
}
err = json.NewEncoder(w).Encode(o) // {"foo": 1}
With struct fields:
type APIResult struct {
Foo int `json:"foo"`
Bar APIIncluded `json:"bar"`
}
type APIIncluded struct {
BarFoo int `json:"barfoo"`
BarBar string `json:"barbar"`
}
f := dynjson.NewFormatter()
res := &APIResult{Foo: 1, Bar: APIIncluded{BarFoo:1, BarBar: "bar"}}
o, err := f.Format(res, []string{"foo", "bar.barfoo"})
if err != nil {
// handle error
}
err = json.NewEncoder(w).Encode(o) // {"foo": 1, "bar":{"barfoo": 1}}
With slices:
type APIResult struct {
Foo int `json:"foo"`
Bar string `json:"bar"`
}
f := dynjson.NewFormatter()
res := []APIResult{{Foo: 1, Bar: "bar"}}
o, err := f.Format(res, []string{"foo"})
if err != nil {
// handle error
}
err = json.NewEncoder(w).Encode(o) // [{"foo": 1}]
type APIResult struct {
Foo int `json:"foo"`
Bar []APIItem `json:"bar"`
}
type APIItem struct {
BarFoo int `json:"barfoo"`
BarBar string `json:"barbar"`
}
f := dynjson.NewFormatter()
res := &APIResult{Foo: 1, Bar: []APIItem{{BarFoo: 1, BarBar: "bar"}}}
o, err := f.Format(res, []string{"foo", "bar.barfoo"})
if err != nil {
// handle error
}
err = json.NewEncoder(w).Encode(o) // {"foo": 1, "bar":[{"barfoo": 1}]}
Limitations
- Anonymous fields without a json tag (embedded by the Go JSON encoder in the enclosing struct) are not supported,
- Maps are copied as is, you cannot filter map contents using
map_field_name.map_key
.
Performance impact
BenchmarkFormat_Fields
BenchmarkFormat_Fields-8 2466639 480 ns/op 184 B/op 7 allocs/op
BenchmarkFormat_NoFields
BenchmarkFormat_NoFields-8 5255031 232 ns/op 32 B/op 1 allocs/op
BenchmarkRawJSON
BenchmarkRawJSON-8 5351313 223 ns/op 32 B/op 1 allocs/op
Contribution guidelines
Contributions are welcome, as long as:
- unit tests & comments are included,
- no external package is used.
License
MIT - See LICENSE
*Note that all licence references and agreements mentioned in the dynjson README section above
are relevant to that project's source code only.