简体   繁体   中英

Dynamically Generate the JSON Schema from the JSON file in JAVA without using the POJO

Any suggestions for getting the JPATH's for the input JSON file. Basically a tree structure of the JSON schema from the JSON file

You should be okay to use JsonParser this way;

First, get the JSON file content as a String. (Say jsonString )
Then code something like this;

JsonParser parser = new JsonParser();
JsonObject o = parser.parse(jsonString).getAsJsonObject();

Once you have the JSON Object, you can use the JsonPath library to get what you may need.

Hope this helps!

try https://github.com/saasquatch/json-schema-inferrer

Json file or string to JsonNode, then

JsonSchemaInferrer.newBuilder()
  .setSpecVersion(SpecVersion.DRAFT_06).build()
  .inferForSample(jsonNode)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM