# Parsing JSON data in Javascript

**URL:** <https://community.smartbear.com/t/parsing-json-data-in-javascript/67>\
**Category:** ReadyAPI\
**Tags:** readyapi, api, migrated\
**Created:** [May 26, 2022, 9:41pm UTC](https://community.smartbear.com/t/parsing-json-data-in-javascript/67 "2022-05-26T21:41:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [May 26, 2022, 9:41pm UTC](https://community.smartbear.com/t/parsing-json-data-in-javascript/67/1 "2022-05-26T21:41:18Z")

</div>

> Originally posted by **david-beltran** on May 26, 2022

I’m trying to sort out how to parse the JSON data from a GET request using an API. The goal is to take the individual fields and save them to Project level variables to use in Property Checkpoints. The code below is the example function from [aqHttpResponse Object | TestComplete Documentation (smartbear.com)](https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqhttpresponse/index.html). The thought is that I should be able to use the line in orange down below, as well as other lines of code, to set the individual fields of the response to variables. I probably have the wrong syntax as I’m not super familiar with Javascript. Is it possible to take the data directly from a GET request and set it to a variable, does the data need to be parsed first, or is this not possible at all in TestComplete?

**function** httpGetRequest()  
{  
**var** address = “[http://httpbin.org](http://httpbin.org)”;

_// Create an aqHttpRequest object_  
**var** aqHttpRequest = aqHttp.CreateGetRequest(address);

_// Send the request, get an aqHttpResponse object_  
**var** aqHttpResponse = aqHttpRequest.Send();

**if** (aqHttpResponse != null)  
{  
_// Read the response data_  
Log.Message(aqHttpResponse.AllHeaders); _// All headers_  
Log.Message(aqHttpResponse.GetHeader(“Content-Type”)); _// A specific header_  
Log.Message(aqHttpResponse.StatusCode); _// A status code_  
Log.Message(aqHttpResponse.StatusText); _// A status text_  
Log.Message(aqHttpResponse.Text); _// A response body_  
// This is the test line, likely the wrong syntax

```
Project.Variables.Name = aqHttpResponse.Text.Name;   

*// Save the response body to a file and place it to the project folder*  
aqHttpResponse.SaveToFile(Project.Path + "body.txt");  

```

}  
}

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [May 27, 2022, 7:30am UTC](https://community.smartbear.com/t/parsing-json-data-in-javascript/67/2 "2022-05-27T07:30:47Z")

</div>

> Originally posted by **ChrisAdams** on May 27, 2022

Hi,

You’ve posted this in the ReadyAPI forum instead of the TestComplete forum. I haven’t used TestComplete, but I’ve done a reasonable amount of Javascript.

The first first I would hone in on are these lines…

```auto
    Log.Message(aqHttpResponse.StatusCode); // A status code
    Log.Message(aqHttpResponse.StatusText); // A status text
    Log.Message(aqHttpResponse.Text); // A response body

```

Did you get a 200 for status code? Did you get a response? Apologies if you know all this already. If you got a 200, you know the service call worked. If you can see that response body in the logs, then it probably is the orange line.

What I cannot tell from the example is whether the service call is asynchronous or synchronous (have a Google on “javascript Fetch API”). It might be that you need to ‘await’ the response before trying to log it.

Lastly, JSON is case-sensitive and quite often data is stored within an array. If you see the data you want to access in square brackets, you need to access it slightly differently. If you could post an excerpt of the JSON, I might be able to help. Beyond that, heopfully someone with more TestComplete experience will be able to reply.

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [May 27, 2022, 1:30pm UTC](https://community.smartbear.com/t/parsing-json-data-in-javascript/67/3 "2022-05-27T13:30:05Z")

</div>

> Originally posted by **david-beltran** on May 27, 2022

I’m using a MLB API for the time being instead of the API for our billing site. I wanted to make sure it could be done before I worked on trying to make it work with our expected data. The JSON data I received was:

{“search\_player\_all”:{“copyRight”:" Copyright 2022 MLB Advanced Media, L.P. Use of any content on this page acknowledges agreement to the terms posted here [http://gdx.mlb.com/components/copyright.txt](http://gdx.mlb.com/components/copyright.txt) “,“queryResults”:{“created”:“2022-05-25T21:28:12”,“totalSize”:“1”,“row”:{“position”:“2B”,“birth\_country”:“USA”,“weight”:“195”,“birth\_state”:“CA”,“name\_display\_first\_last”:“Jeff McNeil”,“college”:“Long Beach State”,“height\_inches”:“1”,“name\_display\_roster”:“McNeil”,“sport\_code”:“mlb”,“bats”:“L”,“name\_first”:“Jeff”,“team\_code”:“nyn”,“birth\_city”:“Santa Barbara”,“height\_feet”:“6”,“pro\_debut\_date”:“2018-07-24T00:00:00”,“team\_full”:“New York Mets”,“team\_abbrev”:“NYM”,“birth\_date”:“1992-04-08T00:00:00”,“throws”:“R”,“league”:“NL”,“name\_display\_last\_first”:“McNeil, Jeff”,“position\_id”:“4”,“high\_school”:“Nipomo, CA”,“name\_use”:“Jeff”,“player\_id”:“643446”,“name\_last”:“McNeil”,“team\_id”:“121”,“service\_years”:”",“active\_sw”:“Y”}}}}

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [May 27, 2022, 3:22pm UTC](https://community.smartbear.com/t/parsing-json-data-in-javascript/67/4 "2022-05-27T15:22:45Z")

</div>

> Originally posted by **ChrisAdams** on May 27, 2022

Hi,

Assuming

```auto
    Log.Message(aqHttpResponse.Text);

```

Logs the response you’ve pasted above, to access name try…

```auto
Log.Message(aqHttpResponse.Text.search_player_all.queryResults.row.name_display_roster);

```

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [May 27, 2022, 7:56pm UTC](https://community.smartbear.com/t/parsing-json-data-in-javascript/67/5 "2022-05-27T19:56:02Z")

</div>

> Originally posted by **david-beltran** on May 27, 2022

When trying to use

```auto
Log.Message(aqHttpResponse.Text.search_player_all.queryResults.row.name_display_roster);

```

I get an error message. The log shows a 200 response from the query and shows the body of the response just as I pasted it in my previous message.

 ![davidbeltran_0-1653680431873.png](https://canada1.discourse-cdn.com/flex049/uploads/smartbear_prod/original/1X/a41ff4104da09091fdd5be28270d4f40f5ad0ad6.png)

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [May 27, 2022, 8:40pm UTC](https://community.smartbear.com/t/parsing-json-data-in-javascript/67/6 "2022-05-27T20:40:38Z")

</div>

> Originally posted by **ChrisAdams** on May 27, 2022

Hi,

It’s a bit difficult drilling into this now as I’m UK-based. I can try and look on Monday, but in the meantime, try building the path incrementally…

```auto
Log.Message(aqHttpResponse);
Log.Message(aqHttpResponse.Text);
Log.Message(aqHttpResponse.Text.search_player_all);
Log.Message(aqHttpResponse.Text.search_player_all.queryResults);

```

I also wonder whether the response has come back as a string and firstly needs to be cast to a JSON Object. Thinking about it, that is likely.

From W3 ([https://www.w3schools.com/js/js\_json\_parse.asp](https://www.w3schools.com/js/js_json_parse.asp))…

```auto
const obj = JSON.parse('{"name":"John", "age":30, "city":"New York"}');
console.log(obj.name);

```

You could try…

```auto
const myObj = JSON.parse(aqHttpResponse.Text); // Cast a string to JSON Object.
Log.message(myObj.Text) // If you get a response here, we're winning.
// Then try and navgigate through your object.

```

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [May 31, 2022, 2:12pm UTC](https://community.smartbear.com/t/parsing-json-data-in-javascript/67/7 "2022-05-31T14:12:34Z")

</div>

> Originally posted by **david-beltran** on May 31, 2022

A combination of the two worked beautifully.

```auto
const hopefulParse = JSON.parse(aqHttpResponse.Text);
    var position = hopefulParse.search_player_all.queryResults.row.position;
    Log.Message(position);

```

Thank you Chris.

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [October 6, 2026, 2:24pm UTC](https://community.smartbear.com/t/parsing-json-data-in-javascript/67/8 "2026-10-06T14:24:57Z")

</div>

Closed on October 6, 2026, 2:24pm UTC

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
