embulk-filter-flatten_json 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/build.gradle +1 -1
- data/src/main/java/org/embulk/filter/flatten_json/FlattenJsonFilterPlugin.java +14 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fff02143a8f84948f96f4a5bf58c08fb1e8724eb
|
4
|
+
data.tar.gz: e87c4459e8b2870d6deaf437152040edeac9d380
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d154754118d8b84c9cfc301da4d9e126166f95c34af41b2bd2db64b6497bcc7abe7a034c1f8c36830b5b6c9942601970d28a17b981c67bfc8a9acb09294dceb
|
7
|
+
data.tar.gz: 51d27e7ea6f610de758b0342b41f6582f078b8cf42883c99b12d28c661bcd1d9df3a7b977200033f92489b9eac507d5ee471ce65d007887b5ed69b4f0bb30a45
|
data/README.md
CHANGED
@@ -30,7 +30,8 @@ c1|c2|c3|json_payload
|
|
30
30
|
|
31
31
|
- **json_columns**: column name list to flatten json (string, required)
|
32
32
|
- **separator**: separator to join keys (string, default: `"."`)
|
33
|
-
- **array_index_prefix**: prefix of array index when joining keys (string, default: `
|
33
|
+
- **array_index_prefix**: prefix of array index when joining keys (string, default: `null`)
|
34
|
+
- if set `null` and **separator** option use the default value, the output become like [JSONPath](http://goessner.net/articles/JsonPath/)
|
34
35
|
|
35
36
|
## Example
|
36
37
|
|
data/build.gradle
CHANGED
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
5
5
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
6
6
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
7
7
|
import com.fasterxml.jackson.databind.node.ValueNode;
|
8
|
+
import com.google.common.base.Optional;
|
8
9
|
import com.google.common.base.Throwables;
|
9
10
|
import com.google.common.collect.Maps;
|
10
11
|
import org.embulk.config.Config;
|
@@ -49,8 +50,8 @@ public class FlattenJsonFilterPlugin
|
|
49
50
|
public String getSeparator();
|
50
51
|
|
51
52
|
@Config("array_index_prefix")
|
52
|
-
@ConfigDefault("
|
53
|
-
public String getArrayIndexPrefix();
|
53
|
+
@ConfigDefault("null")
|
54
|
+
public Optional<String> getArrayIndexPrefix();
|
54
55
|
}
|
55
56
|
|
56
57
|
@Override
|
@@ -142,7 +143,7 @@ public class FlattenJsonFilterPlugin
|
|
142
143
|
}
|
143
144
|
}
|
144
145
|
|
145
|
-
private void setFlattenJsonColumns(PageBuilder pageBuilder, List<Column> flattenJsonColumns, String separator, String arrayIndexPrefix)
|
146
|
+
private void setFlattenJsonColumns(PageBuilder pageBuilder, List<Column> flattenJsonColumns, String separator, Optional<String> arrayIndexPrefix)
|
146
147
|
throws IOException
|
147
148
|
{
|
148
149
|
for (Column flattenJsonColumn: flattenJsonColumns) {
|
@@ -164,7 +165,7 @@ public class FlattenJsonFilterPlugin
|
|
164
165
|
}
|
165
166
|
}
|
166
167
|
|
167
|
-
private void joinNode(String currentPath, JsonNode jsonNode, Map<String, String> map, String separator, String arrayIndexPrefix) {
|
168
|
+
private void joinNode(String currentPath, JsonNode jsonNode, Map<String, String> map, String separator, Optional<String> arrayIndexPrefix) {
|
168
169
|
if (jsonNode.isObject()) {
|
169
170
|
ObjectNode objectNode = (ObjectNode) jsonNode;
|
170
171
|
Iterator<Map.Entry<String, JsonNode>> iterator = objectNode.fields();
|
@@ -176,8 +177,15 @@ public class FlattenJsonFilterPlugin
|
|
176
177
|
}
|
177
178
|
} else if (jsonNode.isArray()) {
|
178
179
|
ArrayNode arrayNode = (ArrayNode) jsonNode;
|
179
|
-
|
180
|
-
|
180
|
+
if (arrayIndexPrefix.isPresent()) {
|
181
|
+
for (int i = 0; i < arrayNode.size(); i++) {
|
182
|
+
joinNode(currentPath + separator + arrayIndexPrefix.get() + i, arrayNode.get(i), map, separator, arrayIndexPrefix);
|
183
|
+
}
|
184
|
+
}
|
185
|
+
else {
|
186
|
+
for (int i = 0; i < arrayNode.size(); i++) {
|
187
|
+
joinNode(currentPath + "[" + i + "]", arrayNode.get(i), map, separator, arrayIndexPrefix);
|
188
|
+
}
|
181
189
|
}
|
182
190
|
} else if (jsonNode.isValueNode()) {
|
183
191
|
ValueNode valueNode = (ValueNode) jsonNode;
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-filter-flatten_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Civitaspo
|
@@ -58,7 +58,7 @@ files:
|
|
58
58
|
- lib/embulk/filter/flatten_json.rb
|
59
59
|
- src/main/java/org/embulk/filter/flatten_json/FlattenJsonFilterPlugin.java
|
60
60
|
- src/test/java/org/embulk/filter/flatten_json/TestFlattenJsonFilterPlugin.java
|
61
|
-
- classpath/embulk-filter-flatten_json-0.0.
|
61
|
+
- classpath/embulk-filter-flatten_json-0.0.2.jar
|
62
62
|
homepage: https://github.com/civitaspo/embulk-filter-flatten_json
|
63
63
|
licenses:
|
64
64
|
- MIT
|