{"id":15043216,"url":"https://github.com/saasquatch/json-schema-inferrer","last_synced_at":"2025-04-13T06:35:34.740Z","repository":{"id":35962227,"uuid":"217615705","full_name":"saasquatch/json-schema-inferrer","owner":"saasquatch","description":"Java library for inferring JSON schema from sample JSONs","archived":false,"fork":false,"pushed_at":"2024-01-31T17:08:54.000Z","size":2105,"stargazers_count":176,"open_issues_count":0,"forks_count":39,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-03-24T10:19:39.041Z","etag":null,"topics":["jackson","java","java-8","java-library","json","json-schema","json-schema-inference","json-schema-inferrer","schemas"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/saasquatch.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-10-25T21:15:07.000Z","updated_at":"2025-03-15T12:49:08.000Z","dependencies_parsed_at":"2024-01-05T19:46:19.587Z","dependency_job_id":"25425024-9fd4-4e2c-9291-f562e965e04e","html_url":"https://github.com/saasquatch/json-schema-inferrer","commit_stats":null,"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saasquatch%2Fjson-schema-inferrer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saasquatch%2Fjson-schema-inferrer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saasquatch%2Fjson-schema-inferrer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saasquatch%2Fjson-schema-inferrer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saasquatch","download_url":"https://codeload.github.com/saasquatch/json-schema-inferrer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248675159,"owners_count":21143763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jackson","java","java-8","java-library","json","json-schema","json-schema-inference","json-schema-inferrer","schemas"],"created_at":"2024-09-24T20:48:42.867Z","updated_at":"2025-04-13T06:35:34.716Z","avatar_url":"https://github.com/saasquatch.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# json-schema-inferrer\n\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n[![JavaCI](https://github.com/saasquatch/json-schema-inferrer/actions/workflows/JavaCI.yml/badge.svg?branch=master)](https://github.com/saasquatch/json-schema-inferrer/actions/workflows/JavaCI.yml)\n[![](https://jitpack.io/v/saasquatch/json-schema-inferrer.svg)](https://jitpack.io/#saasquatch/json-schema-inferrer)\n\nJava library for inferring JSON schema based on sample JSONs.\n\n## Demo site\n\n[Here is a simple demo site](https://json-schema-inferrer.herokuapp.com/) for this library that showcases some of the things it's capable of.\n\n## Sample usage\n\n```java\nimport java.util.Arrays;\nimport com.fasterxml.jackson.databind.JsonNode;\nimport com.fasterxml.jackson.databind.ObjectMapper;\nimport com.saasquatch.jsonschemainferrer.*;\n\npublic class Example {\n\n  private static final ObjectMapper mapper = new ObjectMapper();\n  private static final JsonSchemaInferrer inferrer = JsonSchemaInferrer.newBuilder()\n      .setSpecVersion(SpecVersion.DRAFT_06)\n      // Requires commons-validator\n      .addFormatInferrers(FormatInferrers.email(), FormatInferrers.ip())\n      .setAdditionalPropertiesPolicy(AdditionalPropertiesPolicies.notAllowed())\n      .setRequiredPolicy(RequiredPolicies.nonNullCommonFields())\n      .addEnumExtractors(EnumExtractors.validEnum(java.time.Month.class),\n          EnumExtractors.validEnum(java.time.DayOfWeek.class))\n      .build();\n\n  public static void main(String[] args) throws Exception {\n    final JsonNode sample1 = mapper.readTree(\n        \"{\\\"🙈\\\":\\\"https://saasquatch.com\\\",\\\"🙉\\\":[-1.5,2,\\\"hello@saasquat.ch\\\",false],\\\"🙊\\\":3,\\\"weekdays\\\":[\\\"MONDAY\\\",\\\"TUESDAY\\\"]}\");\n    final JsonNode sample2 = mapper.readTree(\n        \"{\\\"🙈\\\":1,\\\"🙉\\\":{\\\"🐒\\\":true,\\\"🐵\\\":[2,\\\"1234:5678::\\\"],\\\"🍌\\\":null},\\\"🙊\\\":null,\\\"months\\\":[\\\"JANUARY\\\",\\\"FEBRUARY\\\"]}\");\n    final JsonNode resultForSample1 = inferrer.inferForSample(sample1);\n    final JsonNode resultForSample1And2 =\n        inferrer.inferForSamples(Arrays.asList(sample1, sample2));\n    for (JsonNode j : Arrays.asList(sample1, sample2, resultForSample1, resultForSample1And2)) {\n      System.out.println(mapper.writeValueAsString(j));\n    }\n  }\n\n}\n```\n\nIn the code above, `sample1` is:\n\n```json\n{\n  \"🙈\": \"https://saasquatch.com\",\n  \"🙉\": [-1.5, 2, \"hello@saasquat.ch\", false],\n  \"🙊\": 3,\n  \"weekdays\": [\"MONDAY\", \"TUESDAY\"]\n}\n```\n\n`sample2` is:\n\n```json\n{\n  \"🙈\": 1,\n  \"🙉\": { \"🐒\": true, \"🐵\": [2, \"1234:5678::\"], \"🍌\": null },\n  \"🙊\": null,\n  \"months\": [\"JANUARY\", \"FEBRUARY\"]\n}\n```\n\n`resultForSample1` is:\n\n```json\n{\n  \"$schema\": \"http://json-schema.org/draft-06/schema#\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"🙈\": { \"type\": \"string\" },\n    \"🙊\": { \"type\": \"integer\" },\n    \"weekdays\": { \"type\": \"array\", \"items\": { \"enum\": [\"MONDAY\", \"TUESDAY\"] } },\n    \"🙉\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"anyOf\": [\n          { \"type\": [\"number\", \"boolean\"] },\n          { \"type\": \"string\", \"format\": \"email\" }\n        ]\n      }\n    }\n  },\n  \"additionalProperties\": false,\n  \"required\": [\"🙈\", \"🙊\", \"weekdays\", \"🙉\"]\n}\n```\n\nAnd `resultForSample1And2` is:\n\n```json\n{\n  \"$schema\": \"http://json-schema.org/draft-06/schema#\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"🙈\": { \"type\": [\"string\", \"integer\"] },\n    \"months\": { \"type\": \"array\", \"items\": { \"enum\": [\"JANUARY\", \"FEBRUARY\"] } },\n    \"🙊\": { \"type\": [\"null\", \"integer\"] },\n    \"weekdays\": { \"type\": \"array\", \"items\": { \"enum\": [\"MONDAY\", \"TUESDAY\"] } },\n    \"🙉\": {\n      \"anyOf\": [\n        {\n          \"type\": \"object\",\n          \"properties\": {\n            \"🐵\": {\n              \"type\": \"array\",\n              \"items\": {\n                \"anyOf\": [\n                  { \"type\": \"integer\" },\n                  { \"type\": \"string\", \"format\": \"ipv6\" }\n                ]\n              }\n            },\n            \"🍌\": { \"type\": \"null\" },\n            \"🐒\": { \"type\": \"boolean\" }\n          },\n          \"additionalProperties\": false,\n          \"required\": [\"🐵\", \"🐒\"]\n        },\n        {\n          \"type\": \"array\",\n          \"items\": {\n            \"anyOf\": [\n              { \"type\": [\"number\", \"boolean\"] },\n              { \"type\": \"string\", \"format\": \"email\" }\n            ]\n          }\n        }\n      ]\n    }\n  },\n  \"additionalProperties\": false,\n  \"required\": [\"🙈\", \"🙉\"]\n}\n```\n\nFor more examples, see package [`com.saasquatch.jsonschemainferrer.examples`](https://github.com/saasquatch/json-schema-inferrer/tree/master/src/test/java/com/saasquatch/jsonschemainferrer/examples).\n\n## Adding it to your project\n\n### Add the repository\n\nMaven\n\n```xml\n\u003crepositories\u003e\n  \u003crepository\u003e\n    \u003cid\u003ejitpack.io\u003c/id\u003e\n    \u003curl\u003ehttps://jitpack.io\u003c/url\u003e\n  \u003c/repository\u003e\n\u003c/repositories\u003e\n```\n\nGradle\n\n```gradle\nrepositories {\n  maven { url 'https://jitpack.io' }\n}\n```\n\n### Add the dependency\n\nMaven\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.github.saasquatch\u003c/groupId\u003e\n  \u003cartifactId\u003ejson-schema-inferrer\u003c/artifactId\u003e\n  \u003cversion\u003e0.2.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nGradle\n\n```gradle\nimplementation 'com.github.saasquatch:json-schema-inferrer:0.2.1'\n```\n\n### Transitive Dependencies\n\nThis project requires Java 8. The only required transitive dependencies are [Jackson](https://github.com/FasterXML/jackson) and [FindBugs (JSR305)](http://findbugs.sourceforge.net/). If you opt into using some of the built-in [`FormatInferrers`](https://github.com/saasquatch/json-schema-inferrer/blob/master/src/main/java/com/saasquatch/jsonschemainferrer/FormatInferrers.java), [Commons Validator](https://commons.apache.org/proper/commons-validator/) will also be needed. This is encapsulated with a [Gradle feature variant](https://docs.gradle.org/current/userguide/feature_variants.html) named `builtInFormatInferrerSupport`.\n\n### Pre-release Versions\n\nPre-release versions and snapshots (as well as stable releases) can be obtained through [JitPack](https://jitpack.io/#saasquatch/json-schema-inferrer).\n\n## License\n\nUnless explicitly stated otherwise all files in this repository are licensed under the Apache License 2.0.\n\nLicense boilerplate:\n\n```\nCopyright 2023 ReferralSaaSquatch.com, Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaasquatch%2Fjson-schema-inferrer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaasquatch%2Fjson-schema-inferrer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaasquatch%2Fjson-schema-inferrer/lists"}