0

I have a huge JSON and am trying to generate a schema for it that I could use with schema2pojo plugin to generate java classes. I have used these 2 - 1. https://www.jsonschema.net/home AND 2. https://app.quicktype.io/#l=schema online tools to generate the schema.

The first one - https://www.jsonschema.net/home - generates the schema with lot more information for the attributes like below

"properties": {
"ID": {
    "$id": "#/properties/PayLoad/properties/Task/items/anyOf/0/properties/TaskData/properties/ID",
    "type": "string",
    "title": "The ID schema",
    "description": "An explanation about the purpose of this instance.",
    "default": "",
    "examples": [
        "0ab027cc-1e00-4488-b534-002963fa8bb8"
    ]
},

AND

the second one - https://app.quicktype.io/#l=schema - generates the schema that includes format like

"properties": {
    "ID": {
      "type": "string",
      "format": "uuid"
    },

I would like to merge the two schemata that would include the properties from both. Since the JSON is really big, about 3000 lines, I want to avoid manually merging them.

Is there a way I can do this programmatically in Java? Or is anyone aware of an online tool that generates the schema that includes all the properties?

Thank you

I

adbdkb
  • 1,897
  • 6
  • 37
  • 66
  • What have you tried so far? Merging two data structures is fairly straightforward - recursively traverse both structures at the same time and copy all properties over to a third copy. – Ether May 08 '21 at 16:13
  • By the way, the "$id" generated by the first schema is invalid. $ids can never include fragments, like `#/properties/...`. – Ether May 08 '21 at 16:14
  • I tried to merge them as two jsons, but since the structures / jsonpaths are a bit different, I was having trouble. So, I thought I will take the json schema from the first one and based on attribute name, add the format. I know this is not proper way to merge, but wanted to see if I could get that working. So once I get something working,I will try to make it a cleaner implementation. But I am having trouble updating the json in place as I have in this question - https://stackoverflow.com/questions/67239007/update-a-json-to-replace-jsonobject-with-jsonarray - also. Hence posted here – adbdkb May 08 '21 at 16:30

0 Answers0