How to convert sample JSON into JSON schema in Java

倖福魔咒の 提交于 2019-12-20 03:43:17

问题


I want convert json document into json schema. I googled it but not got the exact idea according to my requirement.

here is JSON

 {
 "empId":1001,
 "firstName":"jonh",
 "lastName":"Springer",
 "title": "Engineer",
 "address": {
    "city": "Mumbai",
    "street": "FadkeStreet",
    "zipCode":"420125",
    "privatePhoneNo":{
            "privateMobile": "2564875421",
            "privateLandLine":"251201546"
    }
},
"salary": 150000,
"department":{
     "departmentId": 10521,
     "departmentName": "IT",
     "companyPhoneNo":{
             "cMobile": "8655340546",
             "cLandLine": "10251215465"
      },
     "location":{
             "name": "mulund",
             "locationId": 14500
      }
  }
}

I want to generate like this

   {
   "$schema": "http://json-schema.org/draft-04/schema#",
   "type": "object",
   "title": "Employee",
   "properties": {
     "empId": {
           "type": "integer"
      },
      "firstName":{
           "type":"string"
      },
      "lastName": {
           "type": "string"
      },
      "title": {
           "type": "string"
     },
     "address": {
         "type": "object",
         "properties": {
                       "city": {
                                 "type": "string"
                        },
                        "street": {
                                 "type": "string"
                        },
                        "zipCode": {
                                 "type": "string"
                        },
                       "privatePhoneNo": {
                                 "type": "object",
                                 "properties": {
                                        "privateMobile": {
                                                 "type": "string"
                                         },
                                        "privateLandLine": {
                                                 "type": "string"
                                         }
                                   }
                          }
            }
      },
      "salary": {
            "type": "number"
      },
      "department": {
            "type": "object",
            "properties": {
                   "departmentId": {
                            "type": "integer"
                    },
                    "departmentName": {
                            "type": "string"
                    },
                    "companyPhoneNo": {
                            "type": "object",
                            "properties": {
                                         "cMobile": {
                                              "type": "string"
                                          },
                                         "cLandLine": {
                                              "type": "string"
                                          }
                              }
     },
     "location": {
                 "type": "object",
                 "properties": {
                               "name": {
                                     "type": "string"
                                 },
                              "locationId": {
                                     "type": "integer"
                               }
                   }
      }
    }
   }
 }
}

Is there any library is doing like this or what is another way?


回答1:


https://github.com/perenecabuto/json_schema_generator

http://jsonschema.net/#/

I'm think this maybe will help



来源:https://stackoverflow.com/questions/33910605/how-to-convert-sample-json-into-json-schema-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!