Allen Sparks
Allen Sparks

Reputation: 15

get the response array from a JSON object

I am being asked to write a typescript rest api that consumes an old soap api from a vendor and returns it for internal use. I have not touched javascript in years, so I figure this is a really simple question but I can not seem to solve it.

I have a JSON string which I then parse with JSON.parse(JSONstring) and I get the following object:

{ '$': { TimeStamp: '7/02/2019 11:20AM GMT-07:00',
 version: '1.0',
 WFCVersion: '8.1.3.1531' }, Response: [ { '$': [Object], Schedule: [Array] } ] }

To get that result I am doing: var key1 = JSONbody['Kronos_WFC'] or JSONbody.Kronos_WFC. I am able to get the response with JSONbody.Kronos_WFC.Response but for the life of me I can not get to the Schedule which is what I need

I tried multiple version of JSONbody.Kronos_WFC.Response.Schedule or JSONbody.Kronos_WFC.Schedule All I get is undefined.

Upvotes: 1

Views: 122

Answers (1)

Marie
Marie

Reputation: 167

Try JSONbody.Kronos_WFC.Response[0].Schedule The square brackets in the Response indicate a list or array, and [0] will get the first object in the array.

Upvotes: 1

Related Questions