https://github.com/karpeleslab/pjson
Clone of go's encoding/json with some features such as contexts and group resolution
https://github.com/karpeleslab/pjson
Last synced: 4 months ago
JSON representation
Clone of go's encoding/json with some features such as contexts and group resolution
- Host: GitHub
- URL: https://github.com/karpeleslab/pjson
- Owner: KarpelesLab
- License: bsd-3-clause
- Created: 2023-06-30T02:52:15.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2025-12-14T01:21:25.000Z (6 months ago)
- Last Synced: 2025-12-15T21:28:57.252Z (6 months ago)
- Language: Go
- Size: 244 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://godoc.org/github.com/KarpelesLab/pjson)
# encoding/json fork
This is a fork of `encoding/json` with the following features added:
* Context support: MarshalContext() accepts a context that can be accessed by implementing a variant of MarshalJSON()
* Groups: it is possible to have methods returning groups of values
## Context
Objects can now implement a `MarshalContextJSON(context.Context)` method that will be called over the usual `MarshalJSON()` with
the context of the encoding. `Marshal(v)` will use `context.Background()` by default, and the new `MarshalContext(ctx, v)` receives
a context that will be passed to all objects encoded in the process.
## Grouping
Objects can implement a `GroupMarshalerJSON(ctx context.Context, st *pjson.GroupState) ([]byte, error)` method that will be
called upon marshaling and can use GroupState to specify it needs to gather specific data in batches before rending is possible.
This can be useful when data returned from a json encoding is taken from a database, and many objects access elements from a given
list. These can be grouped in a single SELECT (or similar) from the database, greatly reducing the time needed for render.