hiroyuki-sato/embulk-parser-jsonpath

How can I get json value with field name include dot

jo8937 opened this issue · 4 comments

for example,
json data is

{"user.name" : "george" }

column name include dot.

and jsonpath paraer columns is like this,

  • {name: name, path : user.name, type: string}

then embulk cannot fet json value.
how can i get json value with field name include dot?

Hello, @jo8937

Have you ever tried bracket notation?

in:
  type: file
  path_prefix: example/input
  parser:
    type: jsonpath
    root: "$.['results.name']"
    default_timezone: "Asia/Tokyo"
    columns:
      - { name: "name",          type: string }
      - { name: "city",          type: string }
      - { name: "street_name",   type: string }
      - { name: "zip_code",      type: string }
      - { name: "registered_at", type: timestamp, format: "%Y-%m-%d %H:%M:%S" }
      - { name: "vegetarian",    type: boolean }
      - { name: "age",           type: long }
      - { name: "ratio",         type: double }
out:
  type: stdout
{
  "count": 100,
  "page": 1,
  "results.name": [
    {
      "name": "Hugh Rutherford",
      "city": "Mitchellfurt",
      "street_name": "Ondricka Island",
      "zip_code": "75232",
      "registered_at": "2015-09-09 05:28:45",
      "vegetarian": true,
      "age": 44,
      "ratio": 79.092
    },

Hi, @hiroyuki-sato

name parameter no problem. name parameter is work fine.
But I want use path parameter.
Column name and json field name is not same in my data.
like this.

in:
  type: file
  path_prefix: example/input
  parser:
    type: jsonpath
    root: "$.['results.name']"
    default_timezone: "Asia/Tokyo"
    columns:
      - { name: "name",          type: string }
      - { name: "city",          type: string }
      - { name: "street_name",   type: string, path: "street.name"}
      - { name: "zip_code",      type: string, path: "zip.code" }
      - { name: "registered_at", type: timestamp, format: "%Y-%m-%d %H:%M:%S" }
      - { name: "vegetarian",    type: boolean }
      - { name: "age",           type: long }
      - { name: "ratio",         type: double }
out:
  type: stdout
{
  "count": 100,
  "page": 1,
  "results.name": [
    {
      "name": "Hugh Rutherford",
      "city": "Mitchellfurt",
      "street.name": "Ondricka Island",
      "zip.code": "75232",
      "registered_at": "2015-09-09 05:28:45",
      "vegetarian": true,
      "age": 44,
      "ratio": 79.092
    },
    {
      "name": "AA",
      "city": "BB",
      "street.name": "CC",
      "zip.code": "75232",
      "registered_at": "2015-09-09 05:28:45",
      "vegetarian": true,
      "age": 45,
      "ratio": 79.092
    }
    ]
}

if json fieldname include dot (".") , then path parameter not work.

Hello, @jo8937

Have you ever tried bracket notation too?
It seems that path work fine.

in:
  type: file
  path_prefix: example/input3.json
  parser:
    type: jsonpath
    root: "$.results"
    default_timezone: "Asia/Tokyo"
    columns:
      - { name: "name",          type: string }
      - { name: "city",          type: string }
      - { name: "street_name",   type: string, path: "['street.name']" }
      - { name: "zip_code",      type: string, path: "['zip.code']" }
      - { name: "registered_at", type: timestamp, format: "%Y-%m-%d %H:%M:%S" }
      - { name: "vegetarian",    type: boolean }
      - { name: "age",           type: long }
      - { name: "ratio",         type: double }
out:
  type: stdout
{
  "count": 100,
  "page": 1,
  "results": [
    {
      "name": "Hugh Rutherford",
      "city": "Mitchellfurt",
      "street.name": "Ondricka Island",
      "zip.code": "75232",
      "registered_at": "2015-09-09 05:28:45",
      "vegetarian": true,
      "age": 44,
      "ratio": 79.092
    },
    {
      "name": "Miss Carmella Bashirian",
      "city": "Madilynchester",
      "street.name": "Rhea Walks",
      "zip.code": "44398",
      "registered_at": "2014-07-01 04:25:27",
      "vegetarian": true,
      "age": 73,
      "ratio": 50.608
    }
  ]
}

embulk preview -G config3.yml output the follow.

*************************** 1 ***************************
         name (   string) : Hugh Rutherford
         city (   string) : Mitchellfurt
  street_name (   string) : Ondricka Island
     zip_code (   string) : 75232
registered_at (timestamp) : 2015-09-08 20:28:45 UTC
   vegetarian (  boolean) : true
          age (     long) : 44
        ratio (   double) : 79.092
*************************** 2 ***************************
         name (   string) : Miss Carmella Bashirian
         city (   string) : Madilynchester
  street_name (   string) : Rhea Walks
     zip_code (   string) : 44398
registered_at (timestamp) : 2014-06-30 19:25:27 UTC
   vegetarian (  boolean) : true
          age (     long) : 73
        ratio (   double) : 50.608

Thank you, @hiroyuki-sato !
I understand now. Sorry for my misunderstand in last comment.
It works fine with bracket notation in path parameter.
Thank you again.