Add support for parsing/generating JSON
JSON is a widely used format and pretty much crucial to a lot of software. Inko should provide the means for parsing and generating JSON in the standard library, conforming to RFC 8259 (https://www.rfc-editor.org/rfc/rfc8259).
This is to be implemented in the module std::json
. This module provides high-level module methods such as parse
and generate
, as well as access to the underlying parser. The parser in turn should support limiting object/array nesting, to protect against attacks that involve deeply nested JSON structures.
The method std::json.parse
should support the usual input suspects such as String
, Read
(so basically any file), and ByteArray
. This allows parsing of different input sources without the need for using different methods.
The method std::json.generate
takes a JSON object and serialises it to text. This method doesn't pretty format the JSON.
The type Parser
is used for parsing JSON and exposes extra options, such as the allowed depth. The type Generator
is used to generate JSON, and supports extra options such as "pretty format the JSON" and the indentation level to use. json.parse
and json.generate
use these types under the hoods.
JSON values are represented using a Json
enum, which defines variants such as Null
, True
, Int(Int)
, Float(Float)
, etc. We won't be supporting turning a JSON string into some arbitrary Inko object (e.g. a custom class).