-1

I'm trying to get data from github with this talend job,enter image description here enter image description here

But i couldn't get the data, because it is showing some error.

A JSONObject text must begin with '{' at character 1 of <?xml version="1.0" encoding="UTF-8"?>
<root><root><id>75978949</id><name>Samplerepository</name>

how can i resolve this issue?

This is my output value, when i tested the URL with browser;

[
  {
    "id": 59002981,
    "name": "awesome-ciandcd",
    "full_name": "sample/awesome-ciandcd",
    "owner": {
      "login": "sample",
      "id": 354018,
      "avatar_url": "https://avatars1.githubusercontent.com/u/354018?v=4"

    },
    "private": false,
    "html_url": "https://github.com/sample/awesome-ciandcd",
    "description": "continuous integration and continuous delivery",
    "fork": true,
    "mirror_url": null,
    "open_issues_count": 0,
    "forks": 0,
    "open_issues": 0,
    "watchers": 2,
    "default_branch": "master"
  }
]

I have modified the job like, tRESTClient --> tFileOutputJSON and stored value like below,

[{"string":null,"body":
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <root>
        <id>59002981</id>
        <name>awesome-ciandcd</name>
        <full_name>sample/awesome-ciandcd</full_name>
        <owner>
            <login>sample</login>
            <id>354018</id>
        </owner>
        <private>false</private>
        <fork>true</fork>
        <forks_count>0</forks_count>
        <default_branch>master</default_branch>
    </root>
    <root>
        <id>35035177</id>
        <name>yell-adapters-gelf</name>
        <full_name>sample/yell-adapters-gelf</full_name>
        <owner>
            <login>sample</login>
            <id>354018</id>
        </owner>
        <private>false</private>
        <forks>0</forks>
        <open_issues>0</open_issues>
        <watchers>0</watchers>
        <default_branch>master</default_branch>
    </root>
</root>,"statusCode":200}]

After that, created a job, tFileInputJSON --> tExtractJSONFileds --> tLogRow , but it is throwing error is: fail to parse the json file : C:/Desktop/Output.json

How to handle this issue?

user3114967
  • 639
  • 5
  • 15
  • 38

2 Answers2

1

It's throwing error because response is a JSON array not a simple json object.

You can store the response into a json file. Read the file using tFileInputJSON and then you can extract the values using tExtractJSONFields.

Below is the sample job (I have used above sample data)

sample job

[sample job][1]

Pooja Chauhan
  • 450
  • 4
  • 9
  • After store the result in json output file, tried like above example. But it is throwing an error, fail to parse the json file : C:/Desktop/Output.json – user3114967 Aug 03 '17 at 06:11
  • If i have choose Read By as JsonPath without loop, one record has been generated. But i need to get all the values. 19 counts – user3114967 Aug 03 '17 at 07:05
  • are you getting 19 records in one JSONArray or 19 different JSONArray? – Pooja Chauhan Aug 03 '17 at 09:52
  • in second case you can generate 19 temp files and iterate over them. In first case you just need to change your query. like in tFileInputJSON change read by to jSONPath, Loop JSONquery could be "$[*]", JSONpath query could be "$" and no changes should be required in tExractJSONFields – Pooja Chauhan Aug 03 '17 at 09:59
  • i have single JSONArray with 19 records – user3114967 Aug 03 '17 at 10:47
  • so the solution suggested in above comment should work for you !! – Pooja Chauhan Aug 03 '17 at 11:03
  • I have one more question, if i execute the URL via browser, it is giving JSONArray response. But the same url used in talend tRESTClient & checked in tLogRow, it is giving XML format data. How is this possible? – user3114967 Aug 03 '17 at 11:20
  • what dataType have you set in request header of your tRestClient component ? – Pooja Chauhan Aug 04 '17 at 05:15
  • This URL only used in the tRESTClient component, https://api.github.com/users/sample/repos – user3114967 Aug 04 '17 at 05:49
0

Because its not a JSONObject Its a JSONArray

Put loop path query in tExtractJsonfield component

PreetyK
  • 455
  • 5
  • 14