embulk-parser-json 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9403fc54ab64135da124a3791e34087dda9b62a
4
- data.tar.gz: e3da372fe2d7ab82aac794864b9ff5de2eaf1464
3
+ metadata.gz: 00136715fce9203f8e51e69bad23a9fa32f7f97e
4
+ data.tar.gz: 1ce41b3998ab0e7c9daf4ab4f667235cae993223
5
5
  SHA512:
6
- metadata.gz: 0975db258c9e8b38de2f1b9859b76e3e52a568db92963ad4b53a82e9a954646ef3e34514771f8133d33757702b0912f7a9231b6faf0fd83d266bc046abdd5d2c
7
- data.tar.gz: a35875f4ba86f1dc576b67718e256a2dd91224426c42f5173609ae177ceedf89a788fe3ba47326d3ee5fa05121b304472df28cf97c11aa49c8e323b07367ff67
6
+ metadata.gz: 2a5b8e785d2d61c0a65981dba6ef53617ee797b637b1f80f6a8efe23449965f75e8183b4c53a8555c3ebe42cf9ead5e6c595af67b9e20168b67914230c380925
7
+ data.tar.gz: adef59fdc523f07484f58a96e8acb9314e9019c8c4968e4a41d741f043efc752eb2963d96a108ae196cf17a3413c97a35e0e97b7f021952bffa5a760388f4250
data/README.md CHANGED
@@ -4,18 +4,23 @@ Parser plugin for [Embulk](https://github.com/embulk/embulk).
4
4
 
5
5
  Read data from input as json and fetch each entries by [jsonpath](http://goessner.net/articles/JsonPath/) to output.
6
6
 
7
+
8
+
7
9
  ## Overview
8
10
 
9
11
  * **Plugin type**: parser
10
12
  * **Load all or nothing**: yes
11
13
  * **Resume supported**: no
12
14
 
15
+ ### Breaking changes
16
+
17
+ A type name has been changed from **json** to **jsonpath** from v0.0.3.
13
18
 
14
19
  ## Configuration
15
20
 
16
21
  ```yaml
17
22
  parser:
18
- type: json
23
+ type: jsonpath
19
24
  root: $.response.station
20
25
  schema:
21
26
  - {name: name, type: string}
@@ -26,6 +31,7 @@ parser:
26
31
  - {name: lng, type: double, path: y}
27
32
  - {name: line, type: string}
28
33
  - {name: postal, type: string}
34
+ - {name: optionals, type: json}
29
35
  ```
30
36
 
31
37
  - **type**: specify this plugin as `json`
@@ -58,10 +64,10 @@ schema:
58
64
  - {name: age, type: long}
59
65
  ```
60
66
 
61
- ### Handle more complicated json
67
+ ### Handle more complicated json
62
68
 
63
69
 
64
- If you want to handle more complicated json like as follows:
70
+ If you want to handle more complicated json, you can specify jsonpath to also **path** in schema section like as follows:
65
71
 
66
72
  ```json
67
73
  {
@@ -73,8 +79,6 @@ If you want to handle more complicated json like as follows:
73
79
  }
74
80
  ```
75
81
 
76
- you can specify jsonpath to also **path** in schema section:
77
-
78
82
  ```yaml
79
83
  root: $.students
80
84
  schema:
@@ -83,4 +87,3 @@ schema:
83
87
  ```
84
88
 
85
89
  In this case, names[0] will be firstName of schema and names[1] will be lastName.
86
-
@@ -4,11 +4,11 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "embulk-parser-json"
7
- spec.version = "0.0.2"
7
+ spec.version = "0.0.4"
8
8
  spec.authors = ["Takuma kanari"]
9
9
  spec.email = ["chemtrails.t@gmail.com"]
10
- spec.summary = %q{Embulk parser plugin for json}
11
- spec.description = %q{Json parser plugin is Embulk plugin to fetch entries in json format.}
10
+ spec.summary = %q{Embulk parser plugin for json with jsonpath}
11
+ spec.description = %q{Json parser plugin is Embulk plugin to fetch entries in json format with jsonpath.}
12
12
  spec.homepage = "https://github.com/takumakanari/embulk-parser-json"
13
13
  spec.license = "MIT"
14
14
 
@@ -1,10 +1,11 @@
1
+ require "json"
1
2
  require "jsonpath"
2
3
 
3
4
  module Embulk
4
5
  module Parser
5
6
 
6
- class JsonParserPlugin < ParserPlugin
7
- Plugin.register_parser("json", self)
7
+ class JsonpathParserPlugin < ParserPlugin
8
+ Plugin.register_parser("jsonpath", self)
8
9
 
9
10
  def self.transaction(config, &control)
10
11
  task = {
@@ -18,10 +19,10 @@ module Embulk
18
19
  end
19
20
 
20
21
  def run(file_input)
21
- rootPath = JsonPath.new(@task["root"])
22
+ root = JsonPath.new(@task["root"])
22
23
  schema = @task["schema"]
23
24
  while file = file_input.next_file
24
- rootPath.on(file.read).flatten.each do |e|
25
+ root.on(JSON.parse(file.read)).flatten.each do |e|
25
26
  @page_builder.add(make_record(schema, e))
26
27
  end
27
28
  end
@@ -29,44 +30,39 @@ module Embulk
29
30
  end
30
31
 
31
32
  private
32
-
33
33
  def make_record(schema, e)
34
34
  schema.map do |c|
35
35
  name = c["name"]
36
36
  path = c["path"]
37
- val = path.nil? ? e[name] : find_by_path(e, path)
38
37
 
39
- v = val.nil? ? "" : val
38
+ val = path.nil? ? e[name] : JsonPath.on(e, path).first
40
39
  type = c["type"]
41
40
  case type
42
41
  when "string"
43
- v
42
+ val
44
43
  when "long"
45
- v.to_i
44
+ val.to_i
46
45
  when "double"
47
- v.to_f
46
+ val.to_f
47
+ when "json"
48
+ val
48
49
  when "boolean"
49
- if v.nil?
50
+ if val.nil? || val.empty?
50
51
  nil
51
- elsif v.kind_of?(String)
52
- ["yes", "true", "1"].include?(v.downcase)
53
- elsif v.kind_of?(Numeric)
54
- !v.zero?
52
+ elsif val.kind_of?(String)
53
+ ["yes", "true", "1"].include?(val.downcase)
54
+ elsif val.kind_of?(Numeric)
55
+ !val.zero?
55
56
  else
56
- !!v
57
+ !!val
57
58
  end
58
59
  when "timestamp"
59
- v.empty? ? nil : Time.strptime(v, c["format"])
60
+ val.nil? || val.empty? ? nil : Time.strptime(val, c["format"])
60
61
  else
61
62
  raise "Unsupported type #{type}"
62
63
  end
63
64
  end
64
65
  end
65
-
66
- def find_by_path(e, path)
67
- JsonPath.on(e, path).first
68
- end
69
66
  end
70
-
71
67
  end
72
68
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-parser-json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takuma kanari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-10 00:00:00.000000000 Z
11
+ date: 2016-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonpath
@@ -52,7 +52,8 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
- description: Json parser plugin is Embulk plugin to fetch entries in json format.
55
+ description: Json parser plugin is Embulk plugin to fetch entries in json format with
56
+ jsonpath.
56
57
  email:
57
58
  - chemtrails.t@gmail.com
58
59
  executables: []
@@ -65,7 +66,7 @@ files:
65
66
  - README.md
66
67
  - Rakefile
67
68
  - embulk-parser-json.gemspec
68
- - lib/embulk/parser/json.rb
69
+ - lib/embulk/parser/jsonpath.rb
69
70
  homepage: https://github.com/takumakanari/embulk-parser-json
70
71
  licenses:
71
72
  - MIT
@@ -86,8 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
87
  version: '0'
87
88
  requirements: []
88
89
  rubyforge_project:
89
- rubygems_version: 2.4.5.1
90
+ rubygems_version: 2.5.1
90
91
  signing_key:
91
92
  specification_version: 4
92
- summary: Embulk parser plugin for json
93
+ summary: Embulk parser plugin for json with jsonpath
93
94
  test_files: []