All Projects → saasquatch → json-schema-inferrer

saasquatch / json-schema-inferrer

Licence: Apache-2.0 License
Java library for inferring JSON schema from sample JSONs

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to json-schema-inferrer

cti-stix2-json-schemas
OASIS TC Open Repository: Non-normative schemas and examples for STIX 2
Stars: ✭ 75 (-3.85%)
Mutual labels:  json-schema, schemas
Schema Registry
Confluent Schema Registry for Kafka
Stars: ✭ 1,647 (+2011.54%)
Mutual labels:  json-schema, schemas
Json Schema Validator
A fast Java JSON schema validator that supports draft V4, V6, V7 and V2019-09
Stars: ✭ 292 (+274.36%)
Mutual labels:  json-schema, jackson
jackson-json-reference
JSON Reference for Java with Jackson.
Stars: ✭ 21 (-73.08%)
Mutual labels:  json-schema, jackson
Jsonschema2pojo
Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc
Stars: ✭ 5,633 (+7121.79%)
Mutual labels:  json-schema, jackson
jsonschema-generator
Java JSON Schema Generator – creating JSON Schema (Draft 6, Draft 7, Draft 2019-09, or Draft 2020-12) from Java classes
Stars: ✭ 213 (+173.08%)
Mutual labels:  json-schema, jackson
json2object
Type safe Haxe/JSON (de)serializer
Stars: ✭ 54 (-30.77%)
Mutual labels:  json-schema
form-pa
A flexible and configurable form based on json schema
Stars: ✭ 13 (-83.33%)
Mutual labels:  json-schema
schemaorg-jsd
JSON Schema validation for JSON-LD files using Schema.org vocabulary.
Stars: ✭ 16 (-79.49%)
Mutual labels:  json-schema
yajsv
Yet Another JSON Schema Validator [CLI]
Stars: ✭ 42 (-46.15%)
Mutual labels:  json-schema
schema.data.gouv.fr
Schémas de données ouvertes sur des formats réglementaires ou non
Stars: ✭ 31 (-60.26%)
Mutual labels:  schemas
kloadgen
KLoadGen is kafka load generator plugin for jmeter designed to work with AVRO and JSON schema Registries.
Stars: ✭ 144 (+84.62%)
Mutual labels:  json-schema
JSON-NLP
JSON-NLP Schema for transfer of NLP output using JSON
Stars: ✭ 38 (-51.28%)
Mutual labels:  json-schema
commun
🎩 Fully-featured framework for REST APIs and GraphQL from JSON Schema with TypeScript and MongoDB
Stars: ✭ 97 (+24.36%)
Mutual labels:  json-schema
active model serializers validator
🃏 An extension to ActiveModel::Serializer that validates serializers output against a JSON schema
Stars: ✭ 18 (-76.92%)
Mutual labels:  json-schema
json-schema-sugar
Create a JSON Schema without the pain of writing it 🍦
Stars: ✭ 20 (-74.36%)
Mutual labels:  json-schema
fhir-fuel.github.io
Place to prepare proposal to FHIR about JSON, JSON-Schema, Swagger/OpenAPI, JSON native databases and other JSON-frendly formats (yaml, edn, avro, protobuf etc) and technologies
Stars: ✭ 20 (-74.36%)
Mutual labels:  json-schema
spring-boot-jpa
A Spring Boot microservices reference application using Spring Data JPA
Stars: ✭ 25 (-67.95%)
Mutual labels:  jackson
i18n-tag-schema
Generates a json schema for all i18n tagged template literals in your project
Stars: ✭ 15 (-80.77%)
Mutual labels:  json-schema
schema-shot
Framework-agnostic snapshot testing using "schema by example" for highly dynamic data
Stars: ✭ 34 (-56.41%)
Mutual labels:  json-schema

json-schema-inferrer

License Build Status codecov

Java library for inferring JSON schema based on sample JSONs.

Demo site

Here is a simple demo site for this library that showcases some of the things it's capable of.

Sample usage

import java.util.Arrays;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.saasquatch.jsonschemainferrer.*;

public class Example {

  private static final ObjectMapper mapper = new ObjectMapper();
  private static final JsonSchemaInferrer inferrer = JsonSchemaInferrer.newBuilder()
      .setSpecVersion(SpecVersion.DRAFT_06)
      // Requires commons-validator
      .addFormatInferrers(FormatInferrers.email(), FormatInferrers.ip())
      .setAdditionalPropertiesPolicy(AdditionalPropertiesPolicies.notAllowed())
      .setRequiredPolicy(RequiredPolicies.nonNullCommonFields())
      .addEnumExtractors(EnumExtractors.validEnum(java.time.Month.class),
          EnumExtractors.validEnum(java.time.DayOfWeek.class))
      .build();

  public static void main(String[] args) throws Exception {
    final JsonNode sample1 = mapper.readTree(
        "{\"🙈\":\"https://saasquatch.com\",\"🙉\":[-1.5,2,\"[email protected]\",false],\"🙊\":3,\"weekdays\":[\"MONDAY\",\"TUESDAY\"]}");
    final JsonNode sample2 = mapper.readTree(
        "{\"🙈\":1,\"🙉\":{\"🐒\":true,\"🐵\":[2,\"1234:5678::\"],\"🍌\":null},\"🙊\":null,\"months\":[\"JANUARY\",\"FEBRUARY\"]}");
    final JsonNode resultForSample1 = inferrer.inferForSample(sample1);
    final JsonNode resultForSample1And2 =
        inferrer.inferForSamples(Arrays.asList(sample1, sample2));
    for (JsonNode j : Arrays.asList(sample1, sample2, resultForSample1, resultForSample1And2)) {
      System.out.println(mapper.writeValueAsString(j));
    }
  }

}

In the code above, sample1 is:

{
  "🙈": "https://saasquatch.com",
  "🙉": [-1.5, 2, "[email protected]", false],
  "🙊": 3,
  "weekdays": ["MONDAY", "TUESDAY"]
}

sample2 is:

{
  "🙈": 1,
  "🙉": { "🐒": true, "🐵": [2, "1234:5678::"], "🍌": null },
  "🙊": null,
  "months": ["JANUARY", "FEBRUARY"]
}

resultForSample1 is:

{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "type": "object",
  "properties": {
    "🙈": { "type": "string" },
    "🙊": { "type": "integer" },
    "weekdays": { "type": "array", "items": { "enum": ["MONDAY", "TUESDAY"] } },
    "🙉": {
      "type": "array",
      "items": {
        "anyOf": [
          { "type": ["number", "boolean"] },
          { "type": "string", "format": "email" }
        ]
      }
    }
  },
  "additionalProperties": false,
  "required": ["🙈", "🙊", "weekdays", "🙉"]
}

And resultForSample1And2 is:

{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "type": "object",
  "properties": {
    "🙈": { "type": ["string", "integer"] },
    "months": { "type": "array", "items": { "enum": ["JANUARY", "FEBRUARY"] } },
    "🙊": { "type": ["null", "integer"] },
    "weekdays": { "type": "array", "items": { "enum": ["MONDAY", "TUESDAY"] } },
    "🙉": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "🐵": {
              "type": "array",
              "items": {
                "anyOf": [
                  { "type": "integer" },
                  { "type": "string", "format": "ipv6" }
                ]
              }
            },
            "🍌": { "type": "null" },
            "🐒": { "type": "boolean" }
          },
          "additionalProperties": false,
          "required": ["🐵", "🐒"]
        },
        {
          "type": "array",
          "items": {
            "anyOf": [
              { "type": ["number", "boolean"] },
              { "type": "string", "format": "email" }
            ]
          }
        }
      ]
    }
  },
  "additionalProperties": false,
  "required": ["🙈", "🙉"]
}

For more examples, see package com.saasquatch.jsonschemainferrer.examples.

Adding it to your project

Add the repository

Maven

<repositories>
  <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
  </repository>
</repositories>

Gradle

repositories {
  maven { url 'https://jitpack.io' }
}

Add the dependency

Maven

<dependency>
  <groupId>com.github.saasquatch</groupId>
  <artifactId>json-schema-inferrer</artifactId>
  <version>0.1.4</version>
</dependency>

Gradle

implementation 'com.github.saasquatch:json-schema-inferrer:0.1.4'

Transitive Dependencies

This project requires Java 8. The only required transitive dependencies are Jackson and FindBugs (JSR305). If you opt into using some of the built-in FormatInferrers, Commons Validator will also be needed.

Pre-release Versions

Pre-release versions and snapshots (as well as stable releases) can be obtained through JitPack.

License

Unless explicitly stated otherwise all files in this repository are licensed under the Apache License 2.0.

License boilerplate:

Copyright 2019 ReferralSaaSquatch.com Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].