Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
Hi,
Essayez de reformuler en anglais pour augmenter vos chances d'obtenir une réponse (les gens sont principalement anglophones sur ce forum).
Can you explain what you mean by a good format? What is being sent back by the tRest that you do not like?
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"
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);
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!
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 🙂
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.
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