saasquatch / json-schema-inferrer Goto Github PK
View Code? Open in Web Editor NEWJava library for inferring JSON schema from sample JSONs
License: Apache License 2.0
Java library for inferring JSON schema from sample JSONs
License: Apache License 2.0
Would be nice to get support for spec version 2019-09.
Hello,
I don't know how to install json-schema-inferrer on my computer (install/build java applications is still very opaque to me).
After installing gradle 8.7 through sdk, I tried to follow the guidelines in the README.md, adding the dependencies and repository in build.gradle:
plugins {
id 'java-library'
}
group = 'com.saasquatch'
version = '1.0-SNAPSHOT'
java {
registerFeature('builtInFormatInferrerSupport') {
usingSourceSet(sourceSets.main)
}
}
tasks.compileJava.options.encoding = 'UTF-8'
tasks.compileTestJava.options.encoding = 'UTF-8'
tasks.javadoc.options.encoding = 'UTF-8'
repositories {
mavenCentral()
maven { url 'https://jitpack.io' } # I added this line
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1'
implementation 'com.google.code.findbugs:jsr305:3.0.2'
api 'com.fasterxml.jackson.core:jackson-databind:2.16.1'
builtInFormatInferrerSupportImplementation 'commons-validator:commons-validator:1.8.0'
testImplementation 'com.networknt:json-schema-validator:1.1.0'
testImplementation 'com.google.guava:guava:33.0.0-jre'
implementation 'com.github.saasquatch:json-schema-inferrer:0.2.1' # I added this line also
}
tasks.test {
useJUnitPlatform()
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
}
I don't know if even this is correct.
Next I launched the command:
./gradlew
Which resulted in:
Downloading https://services.gradle.org/distributions/gradle-8.7-bin.zip
............10%.............20%.............30%.............40%............50%.............60%.............70%.............80%.............90%............100%
> Task :help
Welcome to Gradle 8.7.
To run a build, run gradlew <task> ...
To see a list of available tasks, run gradlew tasks
To see more detail about a task, run gradlew help --task <task>
To see a list of command-line options, run gradlew --help
For more detail on using Gradle, see https://docs.gradle.org/8.7/userguide/command_line_interface.html
For troubleshooting, visit https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.7/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD SUCCESSFUL in 15s
1 actionable task: 1 executed
Fine, but I don't see any executable/jar file to launch, so I am stuck. Could you please help me? Thanks.
Description Resource Path Location Type
Missing artifact com.github.saasquatch:json-schema-inferrer:jar:0.2.0 pom.xml /jsontojsonschema line 17 Maven Dependency Problem
The container 'Maven Dependencies' references non existing library 'C:\dev\devtools\cache\m2_repository\com\github\saasquatch\json-schema-inferrer\0.2.0\json-schema-inferrer-0.2.0.jar' jsontojsonschema Build path Build Path Problem
The project cannot be built until build path errors are resolved jsontojsonschema Unknown Java Problem
I noticed that the order of the fields in the schema is different to that of the input json object. I wanted to know whether this was intentional. If so is there a way to predict the field order in the schema? I am using this as an intermediary in one of my libraries and I am having trouble writing the tests as I cannot determine the exact output beforehand. Any help would be much appreciated.
json
{
"int":123,
"double":123.22,
"long":12322222222222222
}
schema
{
"$schema" : "http://json-schema.org/draft-06/schema#",
"type" : "object",
"properties" : {
"int" : {
"type" : "integer"
},
"double" : {
"type" : "number"
},
"long" : {
"type" : "integer"
}
},
"additionalProperties" : false,
"required" : [ "int", "double", "long" ]
}
Hi! This is the best tool out there that converts a sample of json to json schema. Unfortunately I have a requirement that I can only use packages available in the maven central repository. Any chance you can publish it there?
Sometimes, I only want some keys to generate rules, but the current GenericSchemaFeatureInputcan
only get the type and value of the json node, not its key.
For an example:
{
"result": "success",
"msg": "xxxxxxxxx"
}
I want this json gen that json schema:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"result": {
"type": "string",
"const": "success"
},
"msg": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"result",
"msg"
]
}
Now, I can't make rules to generate const only for the field result
.
As this library supports schema draft version upto 7, will there be any update on the latest schema draft version.
JSON Sample:
{
"model_setting": {
"hidden_layers": []
}
}
The format I want looks like this:When the array is empty give items a default value。
{
"type": "object",
"properties": {
"model_setting": {
"type": "object",
"properties": {
"hidden_layers": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
}
My code is as follows
@RequestMapping(value ="/getJsonSchema", method=RequestMethod.POST, produces="application/json;charset=UTF-8")
public String getJsonSchema(@RequestBody Map<String,Object> jsonData) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
JsonSchemaInferrer inferrer = JsonSchemaInferrer.newBuilder()
.setSpecVersion(SpecVersion.DRAFT_04)
.setAdditionalPropertiesPolicy(AdditionalPropertiesPolicies.noOp())
.setDefaultPolicy(DefaultPolicies.useFirstSamples())
.setRequiredPolicy(RequiredPolicies.noOp())
.build();
ObjectNode inferForSample = inferrer.inferForSample(mapper.readTree(mapper.writeValueAsString(jsonData)));
return inferForSample.toPrettyString();
}
The result generated is as follows,no default value
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"model_setting": {
"type": "object",
"properties": {
"hidden_layers": {
"type": "array"
}
}
}
}
}
Hi,
I have an application which depends on json-schema-inferrer. The security report runned with the dependency-check-maven plugin displays a Critical vulnerability CVE-2021-3918.
Reading the report, it says this vulnerability is related to: "json-schema is vulnerable to Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution')".
I forked the repo and I tried to find any dependency to the json-schema it mentions but I couldn't find where it is used further than in the SpecVersion.java:14 as a URL String.
The application where I am using this library cannot be released to production until all critical vulnerability will be fixed. Could you give me any hint about how to resolve this vulnerability?
This is the dependency-check-maven configuration in the pom.xml:
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>7.1.0</version>
<configuration>
<failBuildOnCVSS>7</failBuildOnCVSS>
<skipProvidedScope>true</skipProvidedScope>
<skipRuntimeScope>true</skipRuntimeScope>
<skipTestScope>true</skipTestScope>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
Kind regards
Is there a release that works with Java 8?
A dependency has a vulnerability and should be updated to the latest version (2.13.2.2).
https://mvnrepository.com/artifact/com.github.saasquatch/json-schema-inferrer/0.1.4
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-36518
How to download the jar for this library, I can find only the maven dependency in jitpackio. So I need to know where to download the JAR directly?
What is the long term plan to support and enhance this library?
I am thinking of either creating something myself or betting on this lib.
Are the artifacts published to maven repo?
When the support of draft-08
will be available?
Are you open to contributors PRs?
Just like this article(https://json-schema.org/understanding-json-schema/structuring.html#the-id-property) says, how can i generate a schema with "$id" and "$ref"?
I don't know if this question belongs here, but maybe someone has encountered this issue before.
I basically want to use this library in a production java environment using IntelliJ as the IDE.
After attempting to create a gradle dependency in the IDE, the Maven artifact for this library does not show up in the relevant artifact list.
How to reproduce:
Even adding a custom repository (https://repository.mulesoft.org/nexus/content/repositories/public/) to IntelliJ from the Maven repository website does not help. This directory apparently does not to contain the desired resources.
Any thoughts or help would be greatly appreciated.
I had to clone the repository and then performed mvn clean install
to be able to use the current version.
The best desigin is config the field that can generate const validate.
such as:
JsonSchemaInferrer.newBuilder().setSpecVersion(SpecVersion.DRAFT_07)
.setConstPolicy(ConstPolicies.xxx())
How to generate schema using $ref and $id. Seen this can be achieved using genericSchema interface. Can you share any code snippet or document to show how to use genericschema interface.
it will be better to provide a cli tool, thx
After generated the json schema , we would to generate random fake data with it. Is there any ways of java?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.