jfpoilpret / yeti-json Goto Github PK
View Code? Open in Web Editor NEWSome stuff about typesafe JSON parsing with Yeti
Some stuff about typesafe JSON parsing with Yeti
This module defines functions that can be used from Yeti to parse JSON input string in a typesafe way. To use these functions, you just need to load the "json" module: {readJson, readJson'} = load json; Please also ensure that you put the following jars in the classpath: - json_simple-1.1.jar - json-1.0-SNAPSHOT.jar If you want to use Yeti REPL then you can type the following command line: $ java -cp json_simple-1.1.jar;json-1.0-SNAPSHOT.jar;yeti.jar yeti.lang.compiler.yeti Usage examples follow: > x1 = readJson {a = "", b = 0, c = false} '{"a": "abc", "b": 100, "c": true}'; The first argument acts as a "type template" to which the second argument must be mappable after JSON parsing. An exception will occur if the template type doesn't match the type of the parsed input. Mapping principles follow: JSON type Yeti type Comments --------- --------- -------- object struct all fields from the yeti target struct must exist in JSON object list list if yeti target list is not empty, then item type must match with JSON list items type string string number number boolean boolean anything Some 'a 'a must be convertible to type "anything" null Some 'a in this case, Some 'a is replaced with None () in the result null list<'a> in this case, the result is the empty list [] The mapping is recursive, meaning that if JSON input defines list of lists or structs within structs, then the template should be the same. Other usage examples with lists: > x2 = readJson [] '[1, 2, 3]'; > x2 = readJson [0] '[1, 2, 3]'; The second function takes a list of variants that allows you to specify several different templates that the JSON input may map to; you would use this function as in the following example: > x3 = readJson' [A {a = "", b = 0}, B {b = "", c = false}] '{"a": "abc", "b": 123}'; This allows you to use pattern matching when the JSON input that you get may be of different types.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.