|
5 | 5 | Generates JSON Schema based from JSON data using JAVA |
6 | 6 |
|
7 | 7 | #### Motivation |
8 | | -I have been googling a lot to find a library in JAVA that would generate me a JSON Schema based on the JSON data I have. But the library I found need to have a JAVA class in order to generate a JSON schema. So I made a simple JSON Schema Generator based on JSON data. If there is a library that already exists please let me know (via posting an Issue here) and I will be happy to use it in the current project I am working on. Thanks! |
| 8 | +I have been googling a lot to find a library in JAVA that would generate me a JSON Schema based on the JSON data I have. But most of the libraries I found need to have a JAVA class in order to generate a JSON schema. So I made a simple JSON Schema Generator based on JSON data. If there is a library that already exists please let me know (via posting an Issue here) and I will be happy to use it in the current project I am working on. Thanks! |
9 | 9 |
|
10 | 10 | #### Usage |
11 | 11 | Just call the static method JsonSchemaGenerator.outputAsString or JsonSchemaGenerator.outputAsFile |
12 | 12 | ```java |
13 | 13 | public class GenerateSchema { |
14 | | - public static void main(String[] args) throws IOException { |
15 | | - String json = "{\"sectors\": [{\"times\":[{\"intensity\":30," + |
16 | | - "\"start\":{\"hour\":8,\"minute\":30},\"end\":{\"hour\":17,\"minute\":0}}," + |
17 | | - "{\"intensity\":10,\"start\":{\"hour\":17,\"minute\":5},\"end\":{\"hour\":23,\"minute\":55}}]," + |
18 | | - "\"id\":\"dbea21eb-57b5-44c9-a953-f61816fd5876\"}]}"; |
19 | | - String result = JsonSchemaGenerator.outputAsString(json); |
| 14 | + public static void main(String[] args) throws IOException { |
| 15 | + String json = "{\"sectors\": [{\"times\":[{\"intensity\":30," + |
| 16 | + "\"start\":{\"hour\":8,\"minute\":30},\"end\":{\"hour\":17,\"minute\":0}}," + |
| 17 | + "{\"intensity\":10,\"start\":{\"hour\":17,\"minute\":5},\"end\":{\"hour\":23,\"minute\":55}}]," + |
| 18 | + "\"id\":\"dbea21eb-57b5-44c9-a953-f61816fd5876\"}]}"; |
| 19 | + String result = JsonSchemaGenerator.outputAsString("Schedule", "this is a test", json); |
20 | 20 | /* sample output |
21 | 21 | { |
22 | 22 | "title": "Schedule", |
23 | | - "description": "Test", |
| 23 | + "description": "this is a test", |
24 | 24 | "type": "object", |
25 | 25 | "properties": { |
26 | 26 | "sectors": { |
@@ -68,11 +68,11 @@ public class GenerateSchema { |
68 | 68 | } |
69 | 69 | } |
70 | 70 | */ |
71 | | - |
72 | | - JsonSchemaGenerator.outputAsFile(json, "output-schema.json"); |
73 | | - // the above statement will generate the file on the directory |
74 | | - // where code was executed |
75 | | - } |
| 71 | + |
| 72 | + JsonSchemaGenerator.outputAsFile(json, "output-schema.json"); |
| 73 | + // the above statement will generate the file on the directory |
| 74 | + // where code was executed |
| 75 | + } |
76 | 76 | } |
77 | 77 | ``` |
78 | 78 | #### Author |
|
0 commit comments