AshleyYakeley / Truth

Changes and Pinafore projects. Pull requests not accepted.
https://pinafore.info/
GNU General Public License v2.0
32 stars 0 forks source link

Interpret JSON format #168

Open AshleyYakeley opened 1 year ago

AshleyYakeley commented 1 year ago

Per #180:

datatype storable JSON of
    Null;
    Bool Boolean;
    String Text;
    Number Scientific;
    Array (List JSON);
    Object (List (Text *: JSON)); # constructor function sorts and reduces by key
end;

type storable TextJSON;
subtype TextJSON <: Literal; # (dynamic subtype, text/json)
subtype TextJSON <: Textual;
subtype TextJSON <: Interpretation JSON;

type storable CBORJSON;
subtype CBORJSON <: Literal; # (dynamic subtype, application/cbor)
subtype CBORJSON <: Interpretation JSON;

decode.JSON: Text -> Maybe TextJSON
textual: TextJSON -> Text

prism1: Prism Text TextJSON

textEncode.JSON: JSON -> TextJSON
interpret: TextJSON -> JSON

prism2: Thing TextJSON JSON

Alternative:

type storable JSON;  # constructors as above
subtype JSON <: Literal;  # stored as CBOR
asText.JSON: Prism Text JSON;
asCBOR.JSON: Prism Blob JSON;

fromMedia.JSON: Media -> Maybe JSON;
toTextMedia.JSON: JSON -> Media;
toCBORMedia.JSON: JSON -> Media;