Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
56 lines (48 sloc) 1.36 KB
from webidl`core` import JSON as NativeJSON
from webidl`core` import Object
from webidl`core` import String as NativeString
from webidl`internal` import __serulian_internal as Internal
/**
* JSON defines serialization to/from JSON.
*/
@•typealias('json')
class JSON {
/**
* Get returns a JSON serializer.
*/
constructor Get() { return JSON.new() }
/**
* Stringify returns the JSON string form of the given `mapping`.
*/
function Stringify(value mapping<any>) string {
return string(NativeJSON.stringify(Object(value), Internal.autoUnbox))
}
/**
* Parse parses the given JSON `value` into a Mapping. Will reject on a parse error.
*/
function Parse(value string) mapping<any> {
return mapping<any>(NativeJSON.parse(NativeString(value), Internal.autoBox))
}
}
/**
* Stringifier defines an interface for converting a Mapping into a string form.
*/
@•typealias('$stringifier')
interface Stringifier {
constructor Get() { return JSON.new() }
/**
* Stringify converts a Mapping `value` into a string form.
*/
function Stringify(value mapping<any>) string
}
/**
* Parser defines an interface for parsing a string into a Mapping.
*/
@•typealias('$parser')
interface Parser {
constructor Get() { return JSON.new() }
/**
* Parse parses the given string `value` into a Mapping. Should reject on failure.
*/
function Parse(value string) mapping<any>
}
You can’t perform that action at this time.