Skip to content

Commit

Permalink
Rotate release notes as part of the 0.2.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
ponylang-main committed Jan 22, 2025
1 parent 18b601c commit 78ba2f3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
34 changes: 34 additions & 0 deletions .release-notes/0.2.0.md
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.

34 changes: 0 additions & 34 deletions .release-notes/next-release.md
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.

0 comments on commit 78ba2f3

Please sign in to comment.