Package com.illumon.iris.importers.util
Class JsonInputStream
java.lang.Object
java.io.InputStream
com.illumon.iris.importers.util.JsonInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
A stream that transforms JSON into CSV using a recursive flattening of each JSON object
(one top level JSON object per CSV row).
The input file should contain plain JSON objects, not comma separated or an array.
e.g. the following is a legal file with 3 objects, which will result in 3 rows:
{a:1} {a:2} {a:3}
You may have multiple JSON objects on a single line, and/or the JSON objects may span multiple lines.
Nested objects are recursively expanded, with the column name for each field derived from the full "path" to that
field. The path separator is specified in the constructor. Array elements are numbered with a zero-based index.
For example:
{ "a":1, "b":{ "c":2, "d":3 }, "e":[4,5,6] }
maps to a schema with the columns "a", "b_c", "b_d", "e0", "e1", "e2" and a row with values 1, 2, 3, 4, 5, 6
(the path separator used here is "_")
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionJsonInputStream
(File[] inputFiles, long inferLines, List<String> columnNames, String pathSeparator) -
Method Summary
Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Field Details
-
log
public static final com.fishlib.io.logger.Logger log
-
-
Constructor Details
-
JsonInputStream
public JsonInputStream(File[] inputFiles, long inferLines, List<String> columnNames, String pathSeparator) throws IOException - Throws:
IOException
-
-
Method Details
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-