有一个JSON文件,已将其转换为JSON模式,并以ReasonmL类型进行架构定义。 请帮助评论以下问题。
- 使用JSON模式作为表/模式定义是一个不错的选择吗? 似乎定义表/方案是事实上的标准。如果它 不是建议的方法,请建议我解决的方法 这个问题。
- 是否可以动态定义类型?我会将所有表/方案定义和数据保存到单个JSON文件中。当我解码JSON文件时,所有定义和数据都应同时定义为OCaml / ReasonmL中的类型。有一种替代方法,我可以通过编码将所有表/方案转换为类型,但是我将使它们尽可能灵活。
谢谢。
列表1:Stocks.json
[
{
"code": "AAPL.US","timestamp": 1584388800,"gmtoffset": 0,"open": 241.95,"high": 259.08,"low": 240,"close": 242.21,"volume": 80605865,"previousClose": 277.97,"change": -35.76,"change_p": -12.865
},{
"code": "Abpl.US","change_p": -12.865
}
]
清单2:根据json-schema.org的标准,JSON Schema是从清单1生成的。
{
"$schema": "http://json-schema.org/draft-07/schema","$id": "http://example.com/example.json","type": "array","readOnly": false,"writeonly": false,"uniqueItems": false,"minItems": 0,"minContains": 1,"title": "The Root Schema","description": "The root schema comprises the entire JSON document.","additionalItems": true,"items": {
"$id": "#/items","type": "object","minProperties": 0,"title": "The Items Schema","description": "An explanation about the purpose of this instance.","default": {},"examples": [
{
"code": "AAPL.US","timestamp": 1584388800.0,"gmtoffset": 0.0,"volume": 80605865.0,"low": 240.0,"change_p": -12.865
},{
"volume": 80605865.0,"change_p": -12.865,"code": "Abpl.US","gmtoffset": 0.0
}
],"additionalProperties": true,"required": [
"code","timestamp","gmtoffset","open","high","low","close","volume","previousClose","change","change_p"
],"properties": {
"code": {
"$id": "#/items/properties/code","type": "string","minLength": 0,"title": "The Code Schema","default": "","examples": [
"AAPL.US"
]
},"timestamp": {
"$id": "#/items/properties/timestamp","type": "integer","title": "The Timestamp Schema","default": 0,"examples": [
1584388800
]
},"gmtoffset": {
"$id": "#/items/properties/gmtoffset","title": "The Gmtoffset Schema","examples": [
0
]
},"open": {
"$id": "#/items/properties/open","type": "number","title": "The Open Schema","examples": [
241.95
]
},"high": {
"$id": "#/items/properties/high","title": "The High Schema","examples": [
259.08
]
},"low": {
"$id": "#/items/properties/low","title": "The Low Schema","examples": [
240
]
},"close": {
"$id": "#/items/properties/close","title": "The Close Schema","examples": [
242.21
]
},"volume": {
"$id": "#/items/properties/volume","title": "The Volume Schema","examples": [
80605865
]
},"previousClose": {
"$id": "#/items/properties/previousClose","title": "The Previousclose Schema","examples": [
277.97
]
},"change": {
"$id": "#/items/properties/change","title": "The Change Schema","examples": [
-35.76
]
},"change_p": {
"$id": "#/items/properties/change_p","title": "The Change_p Schema","examples": [
-12.865
]
}
}
}
}
清单3:相应的ReasonmL类型。
type position = {
symbol: string,holding: int,pprice: float,};
type account = {
name: string,max_ind_holding: float,pos: list(position),};