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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf0081e351fe454511db57422dd700ac5a33d87d
4
- data.tar.gz: 0e96abc3127d6c7927d9eb063ad5d9f7da30b452
3
+ metadata.gz: fff02143a8f84948f96f4a5bf58c08fb1e8724eb
4
+ data.tar.gz: e87c4459e8b2870d6deaf437152040edeac9d380
5
5
  SHA512:
6
- metadata.gz: 07e761cc4d4d3a5123717fe5843389fdc51ec0aae4ff55ac40ec00c9430bc854a85ea4c096385e5d2616131e839cc47dfca72ad41b2c67c87ded3bfd1e6c33ca
7
- data.tar.gz: 7a7c2220afba502bb28ad4d7c4575bc29fec509e9a0afe7b67ca32ce69bdd1e3aca1cc2b0bd0342cde55d50dee866d6037f95d28dd7246029eb44082f8b46d59
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
 
@@ -12,7 +12,7 @@ configurations {
12
12
  provided
13
13
  }
14
14
 
15
- version = "0.0.1"
15
+ version = "0.0.2"
16
16
  sourceCompatibility = 1.7
17
17
  targetCompatibility = 1.7
18
18
 
@@ -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
- for (int i = 0; i < arrayNode.size(); i++) {
180
- joinNode(currentPath + separator + arrayIndexPrefix + i, arrayNode.get(i), map, separator, arrayIndexPrefix);
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.1
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.1.jar
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