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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
rayzorsan
Contributor II
Contributor II

Use JSON File as HTTP Body in tREST request

Hi All,

I am trying to use a local JSON file as the body in a request using the tREST component. I also tried the tRESTClient component.

What is the simplest way to take a file and use it in the body of the HTTP request? I want to use the raw input from the file because when I use tMap it keeps escaping the special characters in the JSON.

INPUT:

{

  "name":"Test",

  "fruits":[

   "Apples",

   "Bananas"

  ]

}

OUTPUT:

{

 "fileInfos": [

  {

   "name": "Test",

   "fruits___": "[\"Apples\",\"Bananas\"]"

  }

 ]

}

0695b00000KC3SvAAL.png

Thanks,

Ray

Labels (5)
3 Replies
Anonymous
Not applicable

Hi

Have a try to read the file as a string using tFileInputRaw, pass the string to tRest as Http body (with post method).

 

Regards

Shong

rayzorsan
Contributor II
Contributor II
Author

Hi Shong,

 

Thanks for your reply!

 

I was just finishing up some work with the Raw File components. Seems the key is to use global variables. I have a deadline to meet with this but will post a video or something later about how I am handling complex JSON structures. As it seems nested arrays create some pretty difficult to deal with special characters in the JAVA.

 

Talk soon,

Ray

rayzorsan
Contributor II
Contributor II
Author

Hi All,

 

I was able to do this more simply using Talend and some python locally. You can:

  1. Get the JSONs you need
  2. run python as it is supported natively (tsystem or otherwise)
  3. use tfilelist to reference the jsons
  4. use tjavaflex to connect to a talend rest component
  5. do the operation in the talend rest component ( I used trestclient)

 

Thanks,

Ray