Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
Alpha549
Creator II
Creator II

tRestResponse : return a JSON or XML object

Hello everyone,

 

Here is a simple class (as a routine file) :

 

0695b00000QDtMbAAL.png 

 

Here is a simple REST API job :

 

0695b00000QDtNFAA1.png 

 

0695b00000QDtNtAAL.png 

 

0695b00000QDtOXAA1.png 

 

0695b00000QDtOmAAL.png 

 

0695b00000QDtPLAA1.png 

 

When I use the API, I get this :

 

0695b00000QDtPkAAL.png 

 

Student is displayed a its toString method.

 

I would like to know if it's possible to get a JSON representation of student ?

 

I've thought about a solution : use Google GSON library to convert an object into a JSON string, and return this string instead of the object (student like here).

Can you confirm it's a confortable solution ?

 

Thank you everyone 🙂

Labels (2)
1 Reply
Anonymous
Not applicable

You're essentially posting a String into an XML element. You cannot mix like this. What is the full JSON structure you require?

 

What you need to do here is to build the complete JSON structure and change the Return Body Type of the tRestResponse to String. Then, remove the tXMLMap and simply pass the JSON String (completed) to the body output (which will now be set to String).

 

It should be pointed out that your JSON array has some errors. I believe it should be structured like this....

 

{"root":{"student":{"Person":[{"lastname":"A", "firstname":"B", "age":20, "listeRoles":[ "Etudiant", "Test"]}]}}}

 

You'll need to adjust your routine to enable quotes. The above (hardcoded) in Java would be created like this....

 

String myValue = "{  \"root\":{ \"student\":{ \"Person\":[ { \"lastname\":\"A\", \"firstname\":\"B\", \"age\":20, \"listeRoles\":[ \"Etudiant\", \"Test\" ] } ] } }}";