在使用 json 格式存储配置的时候,老是须要在管理后台写一堆代码,去校验参数是否合法,防止用户乱写。json
最近发现了一个超级好用的工具,能够把开发人员从这个繁琐的工做中解脱出来。api
那就是 json-forms,能够使用 json schema 自动生成表单,方便的一塌糊涂。架构
这是它的demo地址工具
http://brutusin.org/json-forms/
示例 json schema 代码ui
{ "$schema": "http://json-schema.org/draft-03/schema#", "type": "object", "properties": { "species": { "title": "Species supported", "description": "Changes in this property (`$.species`) trigger the resolution of the actual (depending on the values being selected) schema of a dependent property (`$.subspecies`)", "type": "string", "enum": [ "human", "dog", "cat" ], "required": true }, "subspecies": { "dependsOn": [ "species" ] } } }
表单截图this
这是两个在线工具,能够直接将 json 转成 json schema.net
http://yapi.demo.qunar.com/editor/ # 推荐 https://jsonschema.net/
咱们只须要将 json-forms 嵌入到咱们的代码中,就能够使用这个简单高效的工具了。code
更多架构、PHP、GO相关踩坑实践技巧请关注个人公众号:PHP架构师orm