简体   繁体   English

从 Json Schema 生成示例 Json 输出

[英]Generate sample Json output from Json Schema

I want to know whether there is a method in which I can generate sample json output based on a json schema input.我想知道是否有一种方法可以根据 json 模式输入生成示例 json 输出。

for example :-例如 :-

input =>

{
"title": "Example Schema",
"type": "object",
"properties": {
    "firstName": {
        "type": "string"
    },
    "lastName": {
        "type": "string"
    },
    "age": {
        "description": "Age in years",
        "type": "integer",
        "minimum": 0
    }
},
"required": ["firstName", "lastName"]
}

output => 

{     
  "firstName" : "RandomFirstName",
   "lastName" : "RandomLastName"
}

I have a large Json Schema with plenty of validations so to generate a sample valid json I could either create one manually using either Java or just a type it into a file.我有一个包含大量验证的大型 Json Schema,因此要生成一个示例有效 json,我可以使用 Java 手动创建一个,也可以仅将其输入到文件中。 Is there a better way available ?有更好的方法吗?

You can try the JSON Schema Faker .您可以尝试JSON Schema Faker It will take a schema and generate/output a JSON object that will validate against the schema.它将采用模式并生成/输出将针对模式进行验证的 JSON 对象。

JSONBuddy can do this for you. JSONBuddy可以为您做到这一点。 It is a Windows desktop JSON editor and generates live JSON sample data while you are editing your schema.它是一个 Windows 桌面 JSON 编辑器,可在您编辑架构时生成实时 JSON 示例数据。

fake-schema-cli is another option you can use. fake-schema-cli是您可以使用的另一个选项。

Example: fake-schema file-input-schema.json > output.json .示例: fake-schema file-input-schema.json > output.json

You can also use the ModelObject in Adobe Ride (full disclosure: self-plug here).您还可以在 Adob​​e Ride 中使用 ModelObject(完整披露:此处自插)。 Point the ModelObject (or a subclass thereof) to a schema in your java project resources: https://github.com/adobe/ride/blob/develop/sample/sample-service-extension/src/test/java/com/adobe/ride/sample/tests/ObjectCreation.java#L38将 ModelObject(或其子类)指向 Java 项目资源中的模式: https : //github.com/adobe/ride/blob/develop/sample/sample-service-extension/src/test/java/com/ adobe/ride/sample/tests/ObjectCreation.java#L38

You can also use the Ride Fuzzer Lib to easily tests sending negative data into the schema nodes (based on an array of OWASP and google injection test strings, and other various types data): https://github.com/adobe/ride/tree/develop/libraries/ride-fuzzer-lib您还可以使用 Ride Fuzzer Lib 轻松测试将负面数据发送到架构节点(基于一组 OWASP 和 google 注入测试字符串以及其他各种类型的数据): https : //github.com/adobe/ride/树/开发/库/ride-fuzzer-lib

All Ride modules are open source and free: https://github.com/adobe/ride/所有 Ride 模块都是开源且免费的: https : //github.com/adobe/ride/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM