Question: I have an API to fetch the list of employee Name's in an organization and it supports order by clause.
I invoked an API "get /employeeName?$ordeyby=name desc". I got the results like below,

```
{
"value":[
{
  "name":"Sam"
},
{
  "name":"Peter"
},
{
  "name":"Harry"
},
{
  "name":"Arnold"
}]
}

```

I have parsed each name and stored into a variable of string type.

How can I verify using JAVA Script/BeanShell/Groovy, that the returned response is in descending order?

Can anyone please help here. Any of the above-mentioned languages is fine and I want this needs to be implemented in JMeter.

Thanks in advance.

Answer: 
As pointed out in the comments, JSON does not allow control characters in strings. In the case of line breaks, these were encoded as `\n` in the example.

You should definitely consider using a proper library to create the JSON rather than handling the raw strings yourself.
1. Create a POJO which will represent your gist (i.e. object with fields like 'description', 'files' collection. And separate POJO for file containing string fields 'name' and 'content';
2. Do something like this to convert your gist:

```
try {
    GistFile file new GistFile();// Assuming this is POJO for your file
    //Set name and content
    Gist gist = new Gist(); //Asuming this is a POJO for your gist
    gist.addFile(file);
    //Add more files if needed and set other properties
    ObjectMapper mapper = new ObjectMapper();
    String content = mapper.writeValueAsString(gist);
    //Now you have valid JSON string
} catch (Exception e) {
    e.printStackTrace();
}

```

This is for `com.fasterxml.jackson.databind.ObjectMapper` or use different JSON library

3. Actually there are GitHub specific libraries which do most of the job for you. Please refer to this question: [How to connect to github using Java Program](https://stackoverflow.com/questions/48282945/how-to-connect-to-github-using-java-program) it might be helpful