Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
moznion committed May 31, 2020
1 parent c148441 commit b7a38a3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# go-json-ice

Simple, less runtime dependencies and fast JSON marshaler for go and tinygo.
A simple code generator of JSON marshaler for go and tinygo. Generated marshaler has fewer runtime dependencies and it's fast.

## Motivation

Expand Down Expand Up @@ -34,7 +34,7 @@ type AwesomeStruct struct {
}
```

then it generates a marshaler as `MarshalAwesomeStructAsJSON(s *AwesomeStruct) ([]byte, error)`; you can use that like the following:
then it generates marshaler code as `MarshalAwesomeStructAsJSON(s *AwesomeStruct) ([]byte, error)`; you can use that like the following:

```go
marshaled, err := MarshalAwesomeStructAsJSON(&AwesomeStruct{
Expand Down Expand Up @@ -141,6 +141,15 @@ func (f *Foo) MarshalJSON() ([]byte, error) {
}
```

### How to marshal toplevel array and map JSON

It is necessary to generate marshaler code by like the following instructions:

- `//go:generate json-ice --type=[]string --toplevel-array`
- then, it generates a marshaler for toplevel array `[]string` as `MarshalStringArrayAsJSON(st []string) ([]byte, error)`
- `//go:generate json-ice --type=map[string]string --toplevel-map`
- then, it generates a marshaler for toplevel map `map[string]string` as `MarshalStringToStringMapAsJSON(mt map[string]string) ([]byte, error)`

## Restrictions / Known issues

- it cannot marshal `named type` and `type alias` types automatically
Expand Down

0 comments on commit b7a38a3

Please sign in to comment.