Skip to content

Commit

Permalink
Array of objects (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg authored Aug 4, 2023
1 parent 9cd2450 commit d09f379
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

[![build-img]][build-url]
[![pkg-img]][pkg-url]
[![reportcard-img]][reportcard-url]
[![coverage-img]][coverage-url]
[![version-img]][version-url]

Go package to easily construct JSON without defined types.
Expand All @@ -14,6 +12,8 @@ Go package to easily construct JSON without defined types.
* Dependency-free.
* Clean and tested code.

See [docs][pkg-url] for more details.

## Install

Go version 1.18+
Expand Down Expand Up @@ -50,10 +50,6 @@ fmt.Printf("%s\n", raw)

See examples: [example_test.go](example_test.go).

## Documentation

See [these docs][pkg-url] for more details.

## License

[MIT License](LICENSE).
Expand All @@ -62,9 +58,5 @@ See [these docs][pkg-url] for more details.
[build-url]: https://github.com/cristalhq/jsn/actions
[pkg-img]: https://pkg.go.dev/badge/cristalhq/jsn
[pkg-url]: https://pkg.go.dev/github.com/cristalhq/jsn
[reportcard-img]: https://goreportcard.com/badge/cristalhq/jsn
[reportcard-url]: https://goreportcard.com/report/cristalhq/jsn
[coverage-img]: https://codecov.io/gh/cristalhq/jsn/branch/main/graph/badge.svg
[coverage-url]: https://codecov.io/gh/cristalhq/jsn
[version-img]: https://img.shields.io/github/v/release/cristalhq/jsn
[version-url]: https://github.com/cristalhq/jsn/releases
27 changes: 27 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,33 @@ func Example() {
//}
}

func ExampleAO() {
j := jsn.AO{
{"a": 1},
{"b": 2, "c": 3},
{"d": jsn.O{"1": "2"}},
}

raw, _ := json.MarshalIndent(j, "", " ")
fmt.Printf("%s\n", raw)

// Output:
// [
// {
// "a": 1
// },
// {
// "b": 2,
// "c": 3
// },
// {
// "d": {
// "1": "2"
// }
// }
// ]
}

func ExampleNumber() {
j := jsn.O{
"x": 123456.00000000000000000000000000000000000000001,
Expand Down
3 changes: 3 additions & 0 deletions jsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ type A = []any
// O represents JSON object.
type O = map[string]any

// AO represents JSON array of JSON objects.
type AO = []O

// N represents JSON number.
type N string

Expand Down

0 comments on commit d09f379

Please sign in to comment.