Skip to content

Commit

Permalink
Change readme
Browse files Browse the repository at this point in the history
  • Loading branch information
GDLMadushanka committed Oct 14, 2018
1 parent 21b3545 commit 5264a32
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
# JJParser
Java JSON Parser - parser and correct a JSON object according to a given JSON schema

JJParser stands for JAVA JSON Parser which rectifies your JSON input according to a given schema.

- Support JSON schema draft 07
- Structure and data type correction
- Written in Java
- Only depended on Google gson

# Sample usage
> To demonstrate the functionality, let's choose a JSON input string
> which needs both data type and structural corrections.
```java
String schema = "{\n" +
" \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n" +
" \"type\": \"object\",\n" +
" \"properties\": {\n" +
" \"singleObjArray\": {\n" +
" \"type\": \"array\",\n" +
" \"items\": [{\"type\": \"number\"}]\n" +
" }\n" +
" }\n" +
"}";
String inputJson = "{\"singleObjArray\":\"1.618\"}";
String result = JavaJsonParser.parseJson(inputJson, schema);
System.out.println(result);
```
Which will give the following corrected output
```java
{"singleObjArray":[1.618]}
```
### Development

Want to contribute? Great!

You can contribute by
* Adding test cases.
* Reporting issues.
* Updating the project with latest schema changes.
* Add currently unsupported properties like "instaceOf"
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.GDSoft.JJParser</groupId>
<artifactId>JavaJsonParser</artifactId>
<version>2.0-SNAPSHOT</version>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -36,7 +36,6 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
</plugin>

</plugins>
</build>

Expand Down
17 changes: 17 additions & 0 deletions src/test/java/integrationTests/TestJavaJsonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,21 @@ public void testStringMethod() throws ValidatorException, ParserException, IOExc
Assert.assertEquals(expected, result);
}

@Test
public void test2() throws ValidatorException, ParserException {
String schema = "{\n" +
" \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n" +
" \"type\": \"object\",\n" +
" \"properties\": {\n" +
" \"singleObjArray\": {\n" +
" \"type\": \"array\",\n" +
" \"items\": [{\"type\": \"number\"}]\n" +
" }\n" +
" }\n" +
"}";
String inputJson = "{\"singleObjArray\":\"1.618\"}";
String result = JavaJsonParser.parseJson(inputJson, schema);
System.out.println(result);
}

}

0 comments on commit 5264a32

Please sign in to comment.