Skip to content

Commit d09f379

Browse files
authored
Array of objects (#5)
1 parent 9cd2450 commit d09f379

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
[![build-img]][build-url]
44
[![pkg-img]][pkg-url]
5-
[![reportcard-img]][reportcard-url]
6-
[![coverage-img]][coverage-url]
75
[![version-img]][version-url]
86

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

15+
See [docs][pkg-url] for more details.
16+
1717
## Install
1818

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

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

53-
## Documentation
54-
55-
See [these docs][pkg-url] for more details.
56-
5753
## License
5854

5955
[MIT License](LICENSE).
@@ -62,9 +58,5 @@ See [these docs][pkg-url] for more details.
6258
[build-url]: https://github.com/cristalhq/jsn/actions
6359
[pkg-img]: https://pkg.go.dev/badge/cristalhq/jsn
6460
[pkg-url]: https://pkg.go.dev/github.com/cristalhq/jsn
65-
[reportcard-img]: https://goreportcard.com/badge/cristalhq/jsn
66-
[reportcard-url]: https://goreportcard.com/report/cristalhq/jsn
67-
[coverage-img]: https://codecov.io/gh/cristalhq/jsn/branch/main/graph/badge.svg
68-
[coverage-url]: https://codecov.io/gh/cristalhq/jsn
6961
[version-img]: https://img.shields.io/github/v/release/cristalhq/jsn
7062
[version-url]: https://github.com/cristalhq/jsn/releases

example_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,33 @@ func Example() {
3131
//}
3232
}
3333

34+
func ExampleAO() {
35+
j := jsn.AO{
36+
{"a": 1},
37+
{"b": 2, "c": 3},
38+
{"d": jsn.O{"1": "2"}},
39+
}
40+
41+
raw, _ := json.MarshalIndent(j, "", " ")
42+
fmt.Printf("%s\n", raw)
43+
44+
// Output:
45+
// [
46+
// {
47+
// "a": 1
48+
// },
49+
// {
50+
// "b": 2,
51+
// "c": 3
52+
// },
53+
// {
54+
// "d": {
55+
// "1": "2"
56+
// }
57+
// }
58+
// ]
59+
}
60+
3461
func ExampleNumber() {
3562
j := jsn.O{
3663
"x": 123456.00000000000000000000000000000000000000001,

jsn.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ type A = []any
66
// O represents JSON object.
77
type O = map[string]any
88

9+
// AO represents JSON array of JSON objects.
10+
type AO = []O
11+
912
// N represents JSON number.
1013
type N string
1114

0 commit comments

Comments
 (0)