如何在Java中将示例JSON转换为JSON模式
我想将json文档转换为json模式。我在谷歌上搜索了一下,但没有按照我的要求得到确切的想法 这里是JSON如何在Java中将示例JSON转换为JSON模式,java,json,schema,Java,Json,Schema,我想将json文档转换为json模式。我在谷歌上搜索了一下,但没有按照我的要求得到确切的想法 这里是JSON { "empId":1001, "firstName":"jonh", "lastName":"Springer", "title": "Engineer", "address": { "city": "Mumbai", "street": "FadkeStreet", "zipCode":"420125", "privatePhoneNo":
{
"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
}
}
}
我想这样生成
{
"$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"
}
}
}
}
}
}
}
有没有任何图书馆正在这样做,或者有什么其他的方法?
我想这可能会有帮助有一段时间没有人问我这个问题了,但我也遇到了同样的问题。到目前为止,我遇到的最佳解决方案是这个库: 我从json模式文档本身中发现了这一点。它还链接到其他语言的实现:
你试过谷歌吗?您是否正在将json转换为object。如果是,那么这可能会有帮助。否@rupesh_padhye。我想在json模式中转换json文档,还有其他方法吗?是的@Garik Khachanyan,就像我想生成它一样,但我想通过java代码生成。我想创建将json转换为json模式的实用程序。我不明白如何从java代码中使用json_模式_生成器git hub?看这里,它是java的