Class JsonParser
java.lang.Object
org.hl7.fhir.utilities.json.parser.JsonParser
Simple parser for JSON. This parser is not particularly quick (though it's not slow)
The focus for this parser is to faithfully record the line/col number of json elements
so that the FHIR validator can report issues by line number
Also, for the validator, the parser will accept duplicate property names
JSON5: When running in Json5 mode, the parser accepts
* unquoted strings for both fields and values
* missing commas in objects and arrays
* comments - anything starting // will be processed as a comma to the end of the line
Other JSON5 features might be added in the future
The FHIR Validator uses this parser in Json5 mode, and the object model is marked up
with deviations from base JSON spec so that the validator can record them as errors
(this is better than blowing up parsing the JSON)
- Author:
- grahamegrieve
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringcompose(JsonElement element) static Stringcompose(JsonElement element, boolean pretty) static voidcompose(JsonElement element, File file) static voidcompose(JsonElement element, File file, boolean pretty) static voidcompose(JsonElement element, OutputStream stream) static voidcompose(JsonElement element, OutputStream stream, boolean pretty) static byte[]composeBytes(JsonElement element) static byte[]composeBytes(JsonElement element, boolean pretty) static JsonElementparse(byte[] stream) static JsonElementparse(byte[] stream, boolean isJson5) static JsonElementparse(byte[] stream, boolean isJson5, boolean allowDuplicates) static JsonElementstatic JsonElementparse(InputStream stream) static JsonElementparse(InputStream stream, boolean isJson5) static JsonElementparse(InputStream stream, boolean isJson5, boolean allowDuplicates) static JsonElementstatic JsonElementstatic JsonElementstatic JsonElementparseFromFile(String source) static JsonElementparseFromUrl(String source) static JsonElementparseFromUrl(String source, boolean isJson5) static JsonObjectparseObject(byte[] content) static JsonObjectparseObject(byte[] content, boolean isJson5) static JsonObjectparseObject(byte[] stream, boolean isJson5, boolean allowDuplicates) static JsonObjectparseObject(File source) static JsonObjectparseObject(File source, boolean isJson5) static JsonObjectparseObject(InputStream stream) static JsonObjectparseObject(InputStream stream, boolean isJson5) static JsonObjectparseObject(InputStream stream, boolean isJson5, boolean allowDuplicates) static JsonObjectparseObject(String source) static JsonObjectparseObject(String source, boolean isJson5) static JsonObjectparseObject(String source, boolean isJson5, boolean allowDuplicates) static JsonObjectparseObject(String source, boolean isJson5, boolean allowDuplicates, int line) static JsonObjectparseObjectFromFile(String source) static JsonObjectparseObjectFromUrl(String source) static JsonObjectparseObjectFromUrl(String source, boolean isJson5) setSourceName(String sourceName)
-
Constructor Details
-
JsonParser
protected JsonParser() -
JsonParser
-
-
Method Details
-
parseObject
- Throws:
IOExceptionJsonException
-
parseObject
- Throws:
IOExceptionJsonException
-
parseObject
- Throws:
IOExceptionJsonException
-
parseObject
- Throws:
IOExceptionJsonException
-
parseObject
public static JsonObject parseObject(File source, boolean isJson5) throws IOException, JsonException - Throws:
IOExceptionJsonException
-
parseObjectFromFile
- Throws:
IOExceptionJsonException
-
parseObjectFromUrl
- Throws:
IOExceptionJsonException
-
parseObject
public static JsonObject parseObject(InputStream stream, boolean isJson5) throws IOException, JsonException - Throws:
IOExceptionJsonException
-
parseObject
public static JsonObject parseObject(byte[] content, boolean isJson5) throws IOException, JsonException - Throws:
IOExceptionJsonException
-
parseObject
public static JsonObject parseObject(String source, boolean isJson5) throws IOException, JsonException - Throws:
IOExceptionJsonException
-
parseObjectFromUrl
public static JsonObject parseObjectFromUrl(String source, boolean isJson5) throws IOException, JsonException - Throws:
IOExceptionJsonException
-
parseObject
public static JsonObject parseObject(InputStream stream, boolean isJson5, boolean allowDuplicates) throws IOException, JsonException - Throws:
IOExceptionJsonException
-
parseObject
public static JsonObject parseObject(byte[] stream, boolean isJson5, boolean allowDuplicates) throws IOException, JsonException - Throws:
IOExceptionJsonException
-
parseObject
public static JsonObject parseObject(String source, boolean isJson5, boolean allowDuplicates) throws IOException, JsonException - Throws:
IOExceptionJsonException
-
parseObject
public static JsonObject parseObject(String source, boolean isJson5, boolean allowDuplicates, int line) throws IOException, JsonException - Throws:
IOExceptionJsonException
-
parse
- Throws:
IOExceptionJsonException
-
parse
- Throws:
IOExceptionJsonException
-
parse
- Throws:
IOExceptionJsonException
-
parse
- Throws:
IOExceptionJsonException
-
parseFromFile
- Throws:
IOExceptionJsonException
-
parseFromUrl
- Throws:
IOExceptionJsonException
-
parse
public static JsonElement parse(InputStream stream, boolean isJson5) throws IOException, JsonException - Throws:
IOExceptionJsonException
-
parse
- Throws:
IOExceptionJsonException
-
parse
- Throws:
IOExceptionJsonException
-
parseFromUrl
public static JsonElement parseFromUrl(String source, boolean isJson5) throws IOException, JsonException - Throws:
IOExceptionJsonException
-
parse
public static JsonElement parse(InputStream stream, boolean isJson5, boolean allowDuplicates) throws IOException, JsonException - Throws:
IOExceptionJsonException
-
parse
public static JsonElement parse(byte[] stream, boolean isJson5, boolean allowDuplicates) throws IOException, JsonException - Throws:
IOExceptionJsonException
-
parse
public static JsonElement parse(String source, boolean isJson5, boolean allowDuplicates) throws IOException, JsonException - Throws:
IOExceptionJsonException
-
compose
-
compose
- Throws:
IOException
-
compose
- Throws:
IOException
-
composeBytes
-
compose
-
compose
public static void compose(JsonElement element, OutputStream stream, boolean pretty) throws IOException - Throws:
IOException
-
compose
- Throws:
IOException
-
composeBytes
-
getSourceName
-
setSourceName
-