https://github.com/qustavo/chanson
Json Streams Modeling in Go
https://github.com/qustavo/chanson
Last synced: 10 days ago
JSON representation
Json Streams Modeling in Go
- Host: GitHub
- URL: https://github.com/qustavo/chanson
- Owner: qustavo
- License: bsd-2-clause
- Created: 2015-10-31T16:26:56.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-10-29T20:47:48.000Z (over 6 years ago)
- Last Synced: 2025-04-10T05:14:57.384Z (12 days ago)
- Language: Go
- Homepage:
- Size: 16.6 KB
- Stars: 24
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Chanson [](https://travis-ci.org/gchaincl/chanson) [](https://coveralls.io/github/gchaincl/chanson?branch=coveralls)
Package chanson provides a flexible way to construct JSON documents.
As chanson populates Arrays and Objects from functions, it's perfectly suitable for streaming jsons as you build it.
It is not an encoder itself, by default it relies on `json.Encoder` but its flexible enough to let you use whatever you want.# Example
```go
package mainimport (
"bytes"
"fmt""github.com/gchaincl/chanson"
)func main() {
ch := make(chan int)
go func() {
ch <- 1
ch <- 2
ch <- 3
ch <- 4
close(ch)
}()buf := bytes.NewBuffer(nil)
cs := chanson.New(buf)
cs.Array(func(a chanson.Array) {
for i := range ch {
a.Push(i)
}
})fmt.Printf("%v", buf.String())
}
```For more examples and documentarion see the [Godoc](http://godoc.org/github.com/gchaincl/chanson).