An open API service indexing awesome lists of open source software.

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

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).

[![EO principles respected here](https://www.elegantobjects.org/badge.svg)](https://www.elegantobjects.org)

[![Build](https://github.com/kerelape/cjson/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/kerelape/cjson/actions/workflows/build.yml)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](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 main

import (
"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 main

import (
"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+.