You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.doOnValue("/friends/-", it ->System.out.println("Friend: "+ it.readString()))
44
+
.doOnValue("/name", it ->System.out.println("Name: "+ it.readString()))
45
+
.build();
46
+
```
47
+
48
+
The JSON pointers may be specified in any order -- they don't need to match the order the elements appear in the JSON.
49
+
The parser ignores elements that don't match the JSON pointers.
50
+
51
+
When the very nice JSON document is fed to the parser, you'll see this output:
52
+
53
+
```text
54
+
Name: Alice
55
+
Friend: White Rabbit
56
+
Friend: Mad Hatter
57
+
```
58
+
59
+
> **NOTE:** It's important to call `parser.close()` (or use a `try-with-resources` statement) when you're done with the parser.
60
+
61
+
62
+
### Feeding from an InputStream
63
+
64
+
```java
65
+
try (InputStream is = createMyJsonInputStream()) {
66
+
parser.feed(is);
67
+
parser.endOfInput();
68
+
}
69
+
```
70
+
71
+
If you want, you can feed the parser from additional input streams before calling `parser.endOfInput()`.
72
+
73
+
74
+
### Feeding from a byte array
75
+
76
+
You can also feed the parser incrementally.
77
+
This contrived example feeds the parser every byte of an array, one byte at a time:
78
+
79
+
```java
80
+
byte[] bytes = getMyJsonByteArray();
81
+
82
+
for (int offset =0; offset < bytes.length; offset++) {
83
+
int length =1;
84
+
parser.feed(bytes, offset, length);
26
85
}
27
-
```
28
-
A callback associated with `/magicWords/-` is invoked a total of two times: once for `"alakazam"` and once for `"xyzzy"`.
86
+
parser.endOfInput();
87
+
```
88
+
89
+
### Feeding from a java.nio.ByteBuffer
90
+
91
+
There's an overload of `parser.feed()` that takes a ByteBuffer.
92
+
93
+
94
+
### Selecting array elements
95
+
96
+
Normally, a `-` in a JSON Pointer refers to the non-existent element past the end of an array.
97
+
`json-skiff` bends this rule, and interprets `-` as matching _every_ array element.
98
+
99
+
In the previous example we used `/friends/-` to select every element of the `friends` array.
29
100
30
101
The `-` does not need to be the last component of the pointer.
31
102
Consider this JSON document:
@@ -43,12 +114,32 @@ Consider this JSON document:
43
114
}
44
115
```
45
116
46
-
A callback associated with `/widgets/-/serialNumber` is invoked a total of two times: once for `"123"` and once for `"XYZ"`.
117
+
A callback for `/widgets/-/serialNumber` is invoked once for `"123"` and once for `"XYZ"`.
118
+
119
+
120
+
### Selecting whole Objects and Arrays
121
+
122
+
If the target field value is a JSON Array or Object, use `MatchedValue.bytes()` to get the bytes of the Array / Object, and use your favorite JSON processing library to parse it.
123
+
124
+
This is also the recommended way to handle a value whose type is not known at runtime.
125
+
126
+
127
+
### Nullable values
128
+
129
+
If you expect a matched value might be null, check for null by calling `MatchedValue.isNull()` before calling any of the `read*` methods to avoid `NullPointerException`.
47
130
48
131
49
132
## FAQ
50
133
134
+
### How to select only the Nth element of an array?
135
+
136
+
Sorry, this library does not support JSON pointers that reference specific array elements.
137
+
138
+
### How to do more complex matching?
139
+
140
+
If a JSON pointer isn't sufficient, take a look at [JsonSurfer](https://github.com/wanglingsong/JsonSurfer) which lets you use JSON Path to specify complex matching rules.
141
+
51
142
### Is this library an officially supported Couchbase product?
52
143
53
144
No.
54
-
This library is not covered by any Couchbase support contract.
145
+
You are welcome to file issues here on GitHub, but Couchbase Technical Support is not responsible for this library, and it's not covered by any Couchbase support contract.
0 commit comments