Skip to content

Commit b5423c1

Browse files
authored
Update api.md
1 parent dd14406 commit b5423c1

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

api.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,34 @@ title: Json Iterator API
88

99
# API Choices
1010

11-
One thing does not fit all. Jsoniter always put developr friendly as top priority. No matter how many times faster you claim you can be, what most developer need is a json parser just get the job done. JSON being a weak typed data exchange format, when being parsed in language like Java or Go, it is very often we need to deal with type mismatch or uncertain data structure. Existing solution is not only slow to parse, but put too much work on the shoulder of developer. The motivation to reinvent this wheel is not performance, but to make the parsing as easy as it can be. Benchmarking is just a way to get your attention, sadly.
11+
One thing does not fit all. Jsoniter always put developr friendlyness as top priority. No matter how many times faster you claim you can be, what most developer need is a json parser just get the job done. JSON being a weak typed data exchange format, when being parsed in language like Java or Go, it is very often we need to deal with type mismatch or uncertain data structure. Existing solution is not only slow to parse, but put too much work on the shoulder of developer. The motivation to reinvent this wheel is not performance, but to make the parsing as easy as it can be. Benchmarking is just a way to get your attention, sadly.
1212

13-
Jsoniter give you three api style choices:
13+
Jsoniter gives you three api style choices:
1414

1515
* bind-api: which you should stick with most of time
1616
* any-api: when slow is an option
1717
* iterator-api: when maximum flexibility or performance is what needed
1818

1919
And best of all, you can mix them up when parsing one document. Let's see some code
2020

21-
Given this document
21+
Given this document `{"a": {"b": {"c": "d"}}}`
22+
23+
Parse with Go bind-api + any-api
2224

2325
```
26+
type ABC struct {
27+
a Any
28+
}
29+
30+
iter := ParseString(`{"a": {"b": {"c": "d"}}}`)
31+
abc := &ABC{}
32+
iter.Read(&abc)
33+
fmt.Println(abc.a.Get("b", "c"))
2434
```
2535

36+
Tranditionally, parse json return `Object` or `interface{}`. Then the parer's job is done, and developer's nightmare begins. Being able to mix bind-api and any-api, we can leave certain value uncertain, and deal with them later. `Any` has api to extract data out of deeply nested data structure very easily.
37+
38+
2639
# Iterator API
2740

2841
## Motivation

0 commit comments

Comments
 (0)