Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira Server REST API response is a wall of text

Hexploit
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 11, 2020

Hello All

Im fairly new to this so bare with me if im asking stupid questions  :)

I created a script in java that queries Jira server issue, and returns.. wall of text.

I cannot figure out how to receive  formated json response like the ones im seeing all over internet. 

This is how respond looks like, i had to obfuscate some of the text for obvoious resons:

{"expand":"renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations","id":"149225","self":"https://jnjsdasdortal.asdas.jasdasa.net/rest/api/2/issue/149225","key":"SDsasdasCSERVEasda31asd06":null,"customfield_10500":"2020-03-19","customfield_12404":null,"customfield_10501":null,"customfield_12403":null,"customfield_10502":null,"customfield_12406":null,"customfield_10503":null,"customfield_12405":"2020-03-09","customfield_10504":null,"customfield_12408":null,"customfield_12407":null,"lastViewed":"2020-03-11T12:09:58.574+0100","customfield_12000":null,"customfield_12002":null,"customfield_12001":null,"priority":{"self":"https://jnjirasdsatal.asddas.jsadasta.net/rest/api/2/priority/3","iconUrl":"https://jnjasdsasal.asdas.jasdasa.net/images/icons/priorities/medium.svg","name":"Medium","id":"3"},"customfield_12004":null,"customfield_12400":null,"customfield_12003":null,"customfield_12402":"2020-03-09","labels":[],"customfield_12401":"2020-03-06","customfield_11700":null,"customfield_11702":null,"customfield_11701":null

 

My java code:

public class Main {

public static void main(String[] args)throws Exception {



HttpResponse<JsonNode> response = Unirest.get("https://asdasjiraportal.asdasd.asdasds.net/rest/api/2/issue/SERVER-156")

.basicAuth("login", "password")
.header("Accept", "application/json")
.header("Content-Type","application/json")
.asJson();

System.out.println(response.getBody());

 

Can someone guide me where how i can declare formatting or point me to a good resource that is noob friendly?

1 answer

1 accepted

0 votes
Answer accepted
Randy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 11, 2020

json is a data interchange format with no display formatting.  It's up to the rendering client to decide how it chooses to format.  


When you view it in the browser, your browser is detecting it as json and formatting it for you in a way that's more digestible by humans.  

 

In your example code, you'll want to run the response through a json parser to deserialize it.  Then pass that through to a json formatting library to pretty print it to the console.

Hexploit
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 13, 2020

Thank you Randy, this is kind of what i expected : )

Suggest an answer

Log in or Sign up to answer