Skip to content

Instantly share code, notes, and snippets.

@hiroyuki-sato
Last active February 28, 2017 10:52
Show Gist options
  • Save hiroyuki-sato/b117a3bf19bd26214c9d518a48b5785b to your computer and use it in GitHub Desktop.
Save hiroyuki-sato/b117a3bf19bd26214c9d518a48b5785b to your computer and use it in GitHub Desktop.
embulk-parser-jsonpath sample

conf2.yml

in:
  type: file
  path_prefix: test2.json
#  stop_on_invalid_record: false
  parser:
    type: jsonpath
    root: $
    columns:
    - {name: uid, type: string}
    - {name: date, type: string}
    - {name: url, type: string}
    - {name: title, type: string}
    - {name: contents, type: json}
filters:
  - type: expand_json
    root: "$."
    json_column_name: contents
    expanded_columns:
    - { name: "[1][1]", type: string }
  - type: rename
    columns:
      "[1][1]": price
out:
  type: stdout

test2.json

[
  {
    "uid": "20170116-22621624",
    "date": "2017-01-16 00:22:43 +0900",
    "url": "https://www.exmaple.com/foo/bar/",
    "title": "タイトル",
    "contents": [
      [
        "foo_name",
        "あいう"
      ],
      [
        "price",
        "1000"
      ]
    ]
  },
  {
    "uid": "20170116-22621624-2",
    "date": "2017-01-16 00:22:43 +0900",
    "url": "https://www.exmaple.com/foo/bar/",
    "title": "タイトル",
    "contents": [
      [
        "名前",
        "あいう"
      ],
      [
        "値段",
        "千円※キーや値に日本語や半角スペース、記号が入る事もありそれを名寄せする必要がある"
      ]
    ]
  }
]
*************************** 1 ***************************
  uid (string) : 20170116-22621624
 date (string) : 2017-01-16 00:22:43 +0900
  url (string) : https://www.exmaple.com/foo/bar/
title (string) : タイトル
price (string) : 1000
*************************** 2 ***************************
  uid (string) : 20170116-22621624-2
 date (string) : 2017-01-16 00:22:43 +0900
  url (string) : https://www.exmaple.com/foo/bar/
title (string) : タイトル
price (string) : 千円※キーや値に日本語や半角スペース、記号が入る事もありそれを名寄せする必要がある
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment