Package sk.antons.json.parse
Class JsonStream
java.lang.Object
sk.antons.json.parse.JsonStream
Json parer, which traverse json tree and produces stream of json values
according to given path matcher.
Useful, when you have big json and you want to extract only small json
sub tree at once.
Imagine you have jsom like
<pre>
{ "items" : [
{"name": "name-1", "value": 1},
{"name": "name-2", "value": 2},
{"name": "name-3", "value": 3},
{"name": "name-4", "value": 4},
...
]
}
</pre>
So you can parse whole json and iterate parts. In this case whole
json is loaded before traversal. (It is effective for small jsons
only)
<pre>
JsonValue root = JsonParser.parse(inputstream);
root.find(SPM.path("items", "*")).stream()
// or if you want traverse only values
// root.find(SPM.path("items", "*", "value")).stream()
</pre>
This class allows you to read only parts you want. But it is little
bit slower.
<pre>
JsonStream.instance(inputstream, SPM.path("items", "*")).stream();
// or if you want traverse only values
// JsonStream.instance(inputstream, SPM.path("items", "*", "value")).stream();
</pre>
So if you have pretty big json which is json array and you are gounig to
process it item by item, you can use JsonStream with path "*".
- Author:
- antons
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic JsonStreaminstance(Reader reader, PathMatcher matcher) Instance of JsonStream.static JsonStreaminstance(String json, PathMatcher matcher) Instance of JsonStream.static JsonStreaminstance(JsonSource source, PathMatcher matcher) Instance of JsonStream.iterator()Creates iterator for json subparts identifies by given matcher.static voidstream()Creates stream of json subparts identifies by given matcher.
-
Constructor Details
-
JsonStream
Instance of JsonSource- Parameters:
source- source for reading jsonmatcher- path matcher to identify returned values
-
-
Method Details
-
instance
Instance of JsonStream.- Parameters:
source- source for reading jsonmatcher- path matcher to identify returned values- Returns:
- new instance
-
instance
Instance of JsonStream.- Parameters:
json- string with jsonmatcher- path matcher to identify returned values- Returns:
- new instance
-
instance
Instance of JsonStream.- Parameters:
reader- source for reading jsonmatcher- path matcher to identify returned values- Returns:
- new instance
-
iterator
Creates iterator for json subparts identifies by given matcher. After calling the method JsonStream instance is not valid anymore.- Returns:
- iterator
-
stream
Creates stream of json subparts identifies by given matcher. After calling the method JsonStream instance is not valid anymore.- Returns:
- stream
-
main
- Throws:
Exception
-