extractvariable with storing object and getting one of property

maulikhdave
Participant II

i call service out and get Below response in json:

{"data":{"id":2,"email":"janet.weaver@reqres.in","first_name":"Janet","last_name":"Weaver","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/josephstein/128.jpg"}}

and then i store whole json response in variable with variable extractor.

at retrive time i just want email or id ?

Solved Solved
0 4 158
1 ACCEPTED SOLUTION

sidd-harth
Participant V

In your Service callout(SC) policy check the Response tag, by default it is calloutResponse,

<Response>calloutResponse</Response>

After SC use an extract variable(EV) policy,

<ExtractVariables name="ExtractVariables-3">
   <Source>calloutResponse.content</Source>
   <JSONPayload>
      <Variable name="Jobject_id">
         <JSONPath>$.data.id</JSONPath>
      </Variable>
      <Variable name="Jobject_email">
         <JSONPath>$.data.email</JSONPath>
      </Variable>
   </JSONPayload>
   <VariablePrefix>dave</VariablePrefix>
</ExtractVariables>

After EV use a Assign Message Policy,

<AssignMessage name="set-headers-1">
  <Set>
    <Headers>
      <Header name="email">{dave.Jobject_email}</Header>
    </Headers>
  </Set>
  <AssignTo createNew="true" transport="http" type="response"/>
</AssignMessage>

View solution in original post

4 REPLIES 4

Please provide details of what you have tried so far, and clarify what is the issue you are facing so that it's easier to help.

You can use javascript to parse the content of the extracted variable and retrieve the individual fields

{"data":{"id":2,"email":"janet.weaver@reqres.in","first_name":"Janet","last_name":"Weaver","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/josephstein/128.jpg"}}

i m using variable extractor

<JSONPayload> <Variable name="Jobject"> <JSONPath>$.data.*</JSONPath> </Variable> </JSONPayload>

now i want to get "jobject.email"

or jobject.id in assign message policy

<Headers> <Header name="email">{jobject.email}</Header> </Headers>

i dont want to use javascript to parse

sidd-harth
Participant V

In your Service callout(SC) policy check the Response tag, by default it is calloutResponse,

<Response>calloutResponse</Response>

After SC use an extract variable(EV) policy,

<ExtractVariables name="ExtractVariables-3">
   <Source>calloutResponse.content</Source>
   <JSONPayload>
      <Variable name="Jobject_id">
         <JSONPath>$.data.id</JSONPath>
      </Variable>
      <Variable name="Jobject_email">
         <JSONPath>$.data.email</JSONPath>
      </Variable>
   </JSONPayload>
   <VariablePrefix>dave</VariablePrefix>
</ExtractVariables>

After EV use a Assign Message Policy,

<AssignMessage name="set-headers-1">
  <Set>
    <Headers>
      <Header name="email">{dave.Jobject_email}</Header>
    </Headers>
  </Set>
  <AssignTo createNew="true" transport="http" type="response"/>
</AssignMessage>

Not applicable

I personally feel more comfortable using javascript for JSON. That can make you work easy in a single policy.