-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rotate release notes as part of the 0.2.0 release
- Loading branch information
1 parent
18b601c
commit 78ba2f3
Showing
2 changed files
with
34 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## Add JsonExtractor utility class | ||
|
||
We've added a new class to the `JSON` library. `JsonExtractor` bundles up a lot of the boilerplate needed to extract typed values from Json objects. | ||
|
||
Given the following Json: | ||
|
||
```json | ||
{ | ||
"name": "John", | ||
"age": 30, | ||
"isStudent": true | ||
} | ||
``` | ||
|
||
Where you previously had to do: | ||
|
||
```pony | ||
let doc = recover val JsonDoc.>parse(src)? end | ||
let name = (doc.data as JsonOject).data("name")? as String | ||
let age = (doc.data as JsonOject).data("age")? as I64 | ||
let isStudent = (doc.data as JsonOject).data("isStudent")? as Bool | ||
``` | ||
|
||
You can now do: | ||
|
||
```pony | ||
let doc = recover val JsonDoc.>parse(src)? end | ||
let name = JsonExtractor(doc.data)("name")?.as_string()? | ||
let age = JsonExtractor(doc.data)("age")?.as_i64()? | ||
let isStudent = JsonExtractor(doc.data)("isStudent")?.as_bool()? | ||
``` | ||
|
||
For simple Json structures such as the one above, there is little difference. However, once you start dealing with nested objects and arrays, `JsonExtractor` can save you a lot of boilerplate code. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +0,0 @@ | ||
## Add JsonExtractor utility class | ||
|
||
We've added a new class to the `JSON` library. `JsonExtractor` bundles up a lot of the boilerplate needed to extract typed values from Json objects. | ||
|
||
Given the following Json: | ||
|
||
```json | ||
{ | ||
"name": "John", | ||
"age": 30, | ||
"isStudent": true | ||
} | ||
``` | ||
|
||
Where you previously had to do: | ||
|
||
```pony | ||
let doc = recover val JsonDoc.>parse(src)? end | ||
let name = (doc.data as JsonOject).data("name")? as String | ||
let age = (doc.data as JsonOject).data("age")? as I64 | ||
let isStudent = (doc.data as JsonOject).data("isStudent")? as Bool | ||
``` | ||
|
||
You can now do: | ||
|
||
```pony | ||
let doc = recover val JsonDoc.>parse(src)? end | ||
let name = JsonExtractor(doc.data)("name")?.as_string()? | ||
let age = JsonExtractor(doc.data)("age")?.as_i64()? | ||
let isStudent = JsonExtractor(doc.data)("isStudent")?.as_bool()? | ||
``` | ||
|
||
For simple Json structures such as the one above, there is little difference. However, once you start dealing with nested objects and arrays, `JsonExtractor` can save you a lot of boilerplate code. | ||
|
||