Class JsonParser
- java.lang.Object
-
- org.hl7.fhir.utilities.json.parser.JsonParser
-
public class JsonParser extends Object
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 Constructor Description JsonParser()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringcompose(JsonElement element)static Stringcompose(JsonElement element, 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 JsonElementparse(File source)static JsonElementparse(InputStream stream)static JsonElementparse(InputStream stream, boolean isJson5)static JsonElementparse(InputStream stream, boolean isJson5, boolean allowDuplicates)static JsonElementparse(String source)static JsonElementparse(String source, boolean isJson5)static JsonElementparse(String source, boolean isJson5, boolean allowDuplicates)static JsonElementparseFromFile(String source)static JsonElementparseFromUrl(String source)static JsonElementparseFromUrl(String source, boolean isJson5)static JsonObjectparseObject(byte[] stream)static JsonObjectparseObject(byte[] stream, boolean isJson5)static JsonObjectparseObject(byte[] stream, boolean isJson5, boolean allowDuplicates)static JsonObjectparseObject(File source)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 JsonObjectparseObjectFromFile(String source)static JsonObjectparseObjectFromUrl(String source)static JsonObjectparseObjectFromUrl(String source, boolean isJson5)
-
-
-
Constructor Detail
-
JsonParser
public JsonParser()
-
-
Method Detail
-
parseObject
public static JsonObject parseObject(InputStream stream) throws IOException, JsonException
- Throws:
IOExceptionJsonException
-
parseObject
public static JsonObject parseObject(byte[] stream) throws IOException, JsonException
- Throws:
IOExceptionJsonException
-
parseObject
public static JsonObject parseObject(String source) throws IOException, JsonException
- Throws:
IOExceptionJsonException
-
parseObject
public static JsonObject parseObject(File source) throws IOException, JsonException
- Throws:
IOExceptionJsonException
-
parseObjectFromFile
public static JsonObject parseObjectFromFile(String source) throws IOException, JsonException
- Throws:
IOExceptionJsonException
-
parseObjectFromUrl
public static JsonObject parseObjectFromUrl(String source) throws IOException, JsonException
- Throws:
IOExceptionJsonException
-
parseObject
public static JsonObject parseObject(InputStream stream, boolean isJson5) throws IOException, JsonException
- Throws:
IOExceptionJsonException
-
parseObject
public static JsonObject parseObject(byte[] stream, 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
-
parse
public static JsonElement parse(InputStream stream) throws IOException, JsonException
- Throws:
IOExceptionJsonException
-
parse
public static JsonElement parse(byte[] stream) throws IOException, JsonException
- Throws:
IOExceptionJsonException
-
parse
public static JsonElement parse(String source) throws IOException, JsonException
- Throws:
IOExceptionJsonException
-
parse
public static JsonElement parse(File source) throws IOException, JsonException
- Throws:
IOExceptionJsonException
-
parseFromFile
public static JsonElement parseFromFile(String source) throws IOException, JsonException
- Throws:
IOExceptionJsonException
-
parseFromUrl
public static JsonElement parseFromUrl(String source) throws IOException, JsonException
- Throws:
IOExceptionJsonException
-
parse
public static JsonElement parse(InputStream stream, boolean isJson5) throws IOException, JsonException
- Throws:
IOExceptionJsonException
-
parse
public static JsonElement parse(byte[] stream, boolean isJson5) throws IOException, JsonException
- Throws:
IOExceptionJsonException
-
parse
public static JsonElement parse(String source, boolean isJson5) throws IOException, JsonException
- 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
public static String compose(JsonElement element)
-
compose
public static void compose(JsonElement element, OutputStream stream) throws IOException
- Throws:
IOException
-
composeBytes
public static byte[] composeBytes(JsonElement element)
-
compose
public static String compose(JsonElement element, boolean pretty)
-
compose
public static void compose(JsonElement element, OutputStream stream, boolean pretty) throws IOException
- Throws:
IOException
-
composeBytes
public static byte[] composeBytes(JsonElement element, boolean pretty)
-
-