Skip to content

Releases: ponylang/json

0.2.0

22 Jan 16:27
Compare
Choose a tag to compare

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:

{
  "name": "John",
  "age": 30,
  "isStudent": true
}

Where you previously had to do:

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:

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.2.0] - 2025-01-22

Added

  • Add JsonExtractor utility class (PR #19)

0.1.0

10 Feb 17:23
Compare
Choose a tag to compare

Initial library release

The first release of JSON as it's own standard library rather than being part of the Pony standard library.

[0.1.0] - 2023-02-10

Added

  • Initial version (PR #1)