Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

JSON issue not compliant output (Curl - JSON - tREST - TALEND)

Hello,

I have a "tREST" component that I link to a tJSONoutput component
In the tREST I set up a cURL request, the request requests a URL and an "X-Auth-Token" in HTTP header
After that I get a JSON that contains all the metrics of my infrastructures on openstack

the concern is that the json is not the right format, it's a big package of unstructured data in JSON format.

The solution is to add "| python -mjson.tool" at the end of the cURL request.

Like this: curl -H "X-Auth-Token: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX" "XXXXXXXXXXXXXXXXXXXXXX / servers / detail" | python -mjson.tool

This works very well on the bash github console, but I would like to use it on TALEND so that my tREST interopts openstack and generates a JSON with the GOOD FORMAT.

Thank you for your help ...

 

ahmed.daoudi.pro@gmail.com

Labels (5)
13 Replies
TRF
Champion II
Champion II

Hi,

Essayez de reformuler en anglais pour augmenter vos chances d'obtenir une réponse (les gens sont principalement anglophones sur ce forum). 

Anonymous
Not applicable
Author

Hi, my message was in English, it had to translate automatically because I have an automatic translator on my internet pages. Thank you
Anonymous
Not applicable
Author

Can you explain what you mean by a good format? What is being sent back by the tRest that you do not like? 

Anonymous
Not applicable
Author

By "good format" I mean a JSON "normal" with indentations, returns to the line. There with my job TALEND I get a big packet of data, a big block.

MY JSON :

 

{"data":[{"Body":"{\"servers\": [{\"status\": \"ACTIVE\", \"updated\": \"2018-01-23T09:45:02Z\", \"hostId\": \"XXXXXXXXXXXXXXXXXXXXXXX\", \"addresses\": {\"reseau_1\": [{\"XXXXX:mac_addr\": \"XXXXXXXX\", \"version\": 4, \"addr\": \"XXXX\",

good format wich I want:

{

    "servers": [

        {

            "status": "ACTIVE",

            "updated": "2018-01-23T09:45:02Z",

            "hostId": "XXXXXXXXXXXXXXXXXXXXXXXXXX",

            "addresses": {

                "reseau_1": [

                    {

                        "XXXXXXX:mac_addr": "XX:XX:XX:XX:XX:XX",

                        "version": 4,

                        "addr": "XX.XX.XX.XX",

                        "OS-EXT-IPS:type": "fixed"

 

Anonymous
Not applicable
Author

Ah I see. This is relatively easy, but requires a little bit of code. Output your JSON to a tJavaFlex. Assuming the row that enters the tJavaFlex is called "row1", the row that exits the tJavaFlex is called "row2" and the column for the JSON input/output is called "json", this code should work for you....

 

JSONObject json = new JSONObject(row1.json); 
row2.json = json.toString(4); 
Anonymous
Not applicable
Author

ok i will try to do it and tell you what it is. So it's impossible to do as in curl with GIT BASH, just adding "| python -mjson.tool"? It works very well in bash I receive a JSON file in the right format. It would be so much easier to add "| python -mjson.tool" somewhere in talend ... Thank you for your return!

Anonymous
Not applicable
Author

Unfortunately you are comparing Talend to a number of different technologies working together there. You have BASH, Curl and Python working together. I guess you are more familiar with Python than Java, which is why it seems easier. But adding a couple of lines of Java is really very simple and one of the massive advantages of using Talend. Although granted, it does help if you know Java 🙂

Anonymous
Not applicable
Author

your code does not work at home. I think you did not understand what I want then. i have a component tREST that will type on an openstack base in cURL. this component is connected to a tFileOutputJson component, the tFileOutputJson writes all the metrics of my openstack infrastructure in a json file. In this json file I have all the information and metrics I want. But they are not in JSON format, they are poorly structured. With GIT BASH it works fine, I send a cURL request and receive the JSON information, but I would like to do this on TALEND in order to continue and automate my jobs. In addition, with GIT BASH you can not generate a JSON file, it's just the display. As I told you, with GIT BASH just add "| python -mjson.tool" at the end of the request curl and it's very simple. But I do not know where to put the "| python -mjson.tool" with talend. Thanks for your help.

Anonymous
Not applicable
Author

Is it possible to copy / paste this request cURL in TALEND? curl -H "X-Auth-Token: xxxxxxxxxxxxxxxxxxx" "https: //compute.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/servers/detail" | python -mjson.tool