JSON Deserialization on Talend

◇◆丶佛笑我妖孽 提交于 2019-12-14 03:21:36

问题


Trying to figuring out how to deserialize this kind of json in talend components :

            {
          "ryan@toofr.com": {
            "confidence":119,"email":"ryan@toofr.com","default":20
          },
          "rbuckley@toofr.com": {
            "confidence":20,"email":"rbuckley@toofr.com","default":15
          },
          "ryan.buckley@toofr.com": {
            "confidence":18,"email":"ryan.buckley@toofr.com","default":16
          },
          "ryanbuckley@toofr.com": {
            "confidence":17,"email":"ryanbuckley@toofr.com","default":17
          },
          "ryan_buckley@toofr.com": {
            "confidence":16,"email":"ryan_buckley@toofr.com","default":18
          },
          "ryan-buckley@toofr.com": {
            "confidence":15,"email":"ryan-buckley@toofr.com","default":19
          },
          "ryanb@toofr.com": {
            "confidence":14,"email":"ryanb@toofr.com","default":14
          },
          "buckley@toofr.com": {
            "confidence":13,"email":"buckley@toofr.com","default":13
          }
        }

This JSON comes from the Toofr API where documentation can be found here .

Here the actual sitation :

For each line retreived in the database, I call the API and I got this (the first name, the last name and the company change everytime.

Does anyone know how to modify the tExtractJSONField (or use smthing else) to show the results in tLogRow (for each line in the database) ?

Thank you in advance !

EDIT 1:

Here's my tExtractJSONfields :


回答1:


When using tExtractJSONFields with XPath, you need

1) a valid XPath loop point

2) valid XPath mapping to your structure relative to the loop path

Also, when using XPath with Talend, every value needs a key. The key cannot change if you want to loop over it. Meaning this is invalid:

      {
      "ryan@toofr.com": {
        "confidence":119,"email":"ryan@toofr.com","default":20
      },
      "rbuckley@toofr.com": {
        "confidence":20,"email":"rbuckley@toofr.com","default":15
      },

but this structure would be valid:

      {
      "contact": {
        "confidence":119,"email":"ryan@toofr.com","default":20
      },
      "contact": {
        "confidence":20,"email":"rbuckley@toofr.com","default":15
      },

So with the correct data the loop point might be /contact.

Then the mapping for Confidence would be confidence (the name from the JSON), the mapping for Email would be email and vice versa for default.

EDIT

JSONPath has a few disadvantages, one of them being you cannot go higher up in the hierarchy. You can try finding out the correct query with jsonpath.com

The loop expression could be $.*. I am not sure if that will satisfy your need, though - it has been a while since I've been using JSONPath in Talend because of the downsides.




回答2:


I have been ingesting some complex json structures and did this via minimal json libraries, and tjava components within talend.



来源:https://stackoverflow.com/questions/46884609/json-deserialization-on-talend

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!