分享一个自己写的 json-schema 生成工具 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
爱意满满的作品展示区。
sean2009

分享一个自己写的 json-schema 生成工具

  •  
  •   sean2009 Dec 29, 2017 10791 views
    This topic created in 3055 days ago, the information mentioned may be changed or developed.

    介绍

    JSON-SCHEMA 是一种基于 JSON 格式定义 JSON 数据结构的规范,有如下特性:

    1. 描述现有数据格式。
    2. 干净的人类和机器可读的文档。
    3. 完整的结构验证,有利于自动化测试。
    4. 完整的结构验证,可用于验证客户端提交的数据。

    json-schema 演示

    { "type": "object", "properties": { "id": { "type": "integer" }, "name": { "type": "string" }, "price": { "type": "number", "minimum": 0, "exclusiveMinimum": true } }, "required": ["id", "name"] } 

    Why

    作者为什么开发一个 easy-Json-schema 工具呢,就是为了简化 json-schema 定义,大家看看上面的 json 定义,一个很简单结构的 json 用了非常多的字段定义,书写起来非常麻烦。

    easy-json-schema

    如果用 easy-json-schema 定义上面的 json 结构,是非常清晰和易用的。

    { "*id": "integer", "*type": "string", "price":{ "type": "number", "minimum": 0, "exclusiveMinimum": true } } 

    感兴趣的朋友可以关注下

    github: github.com/easy-json-schema

    在线演示: easy-json-schema.github.io

    3 replies    2017-12-30 17:10:19 +08:00
    Death
        1
    Death  
       Dec 30, 2017 via Android
    这样简化会产生模糊性吧?比如 type 作为属性名时?

    比如这个
    {
    "**id": "string",
    "name": "string",
    "type":"number"
    }
    sean2009
        2
    sean2009  
    OP
       Dec 30, 2017 via Android
    如果 type 作为属性名,可以这么写

    type: {type: number}
    About     Help     Advertise     Blog     API     FAQ     Solana     3251 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 34ms UTC 13:38 PVG 21:38 LAX 06:38 JFK 09:38
    Do have faith in what you're doing.
    ubaomsnsnddmindexpchomeyahoorakutenmypapermeadowduckbidyahooyoubaozxmzxmasdabnvcgcvbfgdfscvmmhjkxxddcyybgbzznbnccubaouaituacvGXCVETGDGYHFGBCVBFJFHCBRECBCGDGET54WRWRRWERWREWWRWERRWERSDGEWSFDSFSFfbbsubaofhddfgewrdgdfewwrewwretruyutututdfgfgdgdfgtetgdfgtdfgdert4gdfggwr235wer3wevsdfsdfgdfertxcvsdfrwerhfddfgcvbrwfafbdfhjghbmnlghrtygfdscxvxcvxcsvdasfdffgdcvsdftertsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfshasha9178shasha9178shasha9178shasha9178shasha9178liflif2liflif2liflif2liflif2liflif2liblib3liblib3liblib3liblib3liblib3zhazha444zhazha444zhazha444zhazha444zhazha444dende5dendedendendenden2denden21fenfen9fenf619fen619fenfe9fe619sdfsdfsdfsdfsdfzhazh90zhazh0zhaa50zha90zh590zhozhozzhozhzhozhozhozho2lislislls95lili95lils5liss9sdf0ty987sdft876sdft9876sdf09876sd0t9876sdf0ty98sdf0976sdf0ty986sdf0ty96sdf0t76sdf0876df0ty98sf0t876sd0ty76sdy76sdf76sdf0t76sdf0ty9sdf0ty98sdf0ty987sdf0ty98sdf6676sdf876sd876sd876sdf6sdf6sdf9876sdf0tsdf06sdf0ty9776sdf0ty9776sdf0ty76sdf8876sdf0tsd6sdf06s688876sd688sdf86
    slgz
        3
    slgz  
       Dec 30, 2017
    工具很好, 我选择 JSON-handle