https://github.com/kerelape/cjson
an object-oriented JSON library for Go
https://github.com/kerelape/cjson
go golang immutability json library oop
Last synced: 6 months ago
JSON representation
an object-oriented JSON library for Go
- Host: GitHub
- URL: https://github.com/kerelape/cjson
- Owner: kerelape
- License: mit
- Created: 2023-04-08T13:49:59.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-13T09:30:38.000Z (over 2 years ago)
- Last Synced: 2025-04-06T17:23:32.186Z (7 months ago)
- Topics: go, golang, immutability, json, library, oop
- Language: Go
- Homepage:
- Size: 48.8 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Convenient JSON
Convenient JSON (cjson) is a highly inspired by [eo-json](https://github.com/objectionary/eo-json), object-oriented JSON library for Go (golang).
[](https://www.elegantobjects.org)
[](https://github.com/kerelape/cjson/actions/workflows/build.yml)
[](https://github.com/kerelape/cjson/blob/main/LICENSE.txt)## How to use this library
### Add `cjson` to your Go module
```bash
$ go get -u github.com/kerelape/cjson
```### Build JSON
```go
package mainimport (
"encoding/json"cjson "github.com/kerelape/cjson/pkg"
)func main() {
object := cjson.NewObject().With("key", cjson.NewString("value"))
bytes, err := json.Marshal(object)
if err != nil {
panic(err)
}
println(string(bytes))
}
```### Parse JSON
```go
package mainimport (
"encoding/json"cjson "github.com/kerelape/cjson/pkg"
)func main() {
root, err := cjson.NewDocument([]byte(`{"a":"b"}`)).Parse()
if err != nil {
panic(err)
}
println(root.Object().Value().Found("a").Value().String().Value().Content())
}
```## How to Contribute
Fork this repository, make changes, send us a pull request. We will review your changes and apply them to the `main` branch shortly, provided they don't violate our quality standards. To avoid frustration, before sending us your pull request please run the tests:
```bash
$ go test -v ./...
```You will need Go 1.20+.