Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

path typecasting #32

Open
kakoni opened this issue Mar 28, 2022 · 3 comments
Open

path typecasting #32

kakoni opened this issue Mar 28, 2022 · 3 comments

Comments

@kakoni
Copy link

kakoni commented Mar 28, 2022

I have json data that looks like this;

{
 "attributes": [{
          "attributeName": "Abbreviation",
          "attributeValue": ["Pt-ACTH-R1"]
        }, {
          "attributeName": "ShortName",
          "attributeValue": ["Pt-Adrenokortikotropiini-koe, lyhyt"]
        }, {
          "attributeName": "LongName",
          "attributeValue": ["Pt-Adrenokortikotropiini-koe, lyhyt"]
        }, {
          "attributeName": "Erikoisala",
          "attributeValue": ["K"]
        }, {
          "attributeName": "Langt_namn",
          "attributeValue": ["Pt-Adrenokortikotropin-test, kort"]
        }, {
          "attributeName": "Yksikko",
          "attributeValue": ["Lomake"]
        }]
}

I wish to get attribate name/value pairs into columns;

    columns:
      - {name: "abreviation", type: string, path: "$.attributes[?(@.attributeName== 'Abbreviation')].attributeValue[0]"}

This almost works ok, but gives me string value that has brackets;

["Pt-ACTH-R1"]

Wonder if there is a away to extract just the string value?

@hiroyuki-sato
Copy link
Owner

I'm the maintainer of this plugin, but I'm not familiar JSONPath 😄

Have you ever tried the following?

in:
  type: file
  path_prefix: ./test.txt
  parser:
    type: jsonpath
    columns:
    - {name: "abreviation", type: string, path: "$.attributeValue[0]"}
    root: "$.attributes[?(@.attributeName== 'Abbreviation')]"
out:
  type: stdout

embulk preview shows the following output.

+--------------------+
| abreviation:string |
+--------------------+
|         Pt-ACTH-R1 |
+--------------------+

@kakoni
Copy link
Author

kakoni commented Mar 30, 2022

Right, thanks. In my use case, I need to pick all of those values, meaning something like

      - {name: "abreviation", type: string, path: "$.attributes[?(@.attributeName== 'Abbreviation')].attributeValue[0]"}
      - {name: "short_name", type: string, path: "$.attributes[?(@.attributeName== 'ShortName')].attributeValue[0]"}
...

So using root isn't an option.

@hiroyuki-sato
Copy link
Owner

Hello, @kakoni

embulk-parser-jsonpath expects to specify a root path for input data.
I think it raises an error if you don't use root attributes.
Can you parse your data even incompletely?

I think it requires implementing that feature.

Could you show me your configuration?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants