Support Questions

Find answers, ask questions, and share your expertise

How do I extract the attributes from the below json

avatar
Explorer

Please can you give me an example of how i would extract the "test" values from the below json 

 

I tried the following but not winning , 

 

$.outputs.name.test1 

$.test1

$.outputs.test1

 

I am using the processor "evaluate json path"

 

The below is a response from a webservice I am calling . I want the "test" values to be inserted in a sql table 

 

"outputs": [
{
"name": "test1",
"value": "1"
},
{
"name": "test2",
"value": 0.9512272865085364
},
{
"name": "test3",
"value": 0.9512272865085364
},
{
"name": "test4",
"value": "1"
},
{
"name": "test5",
"value": 4.4659
},
{
"name": "test6",
"value": 0.048772713491463618
}
]
}

1 ACCEPTED SOLUTION

avatar
Explorer

Ok so me and my mate figured it out :). Finally!

 

its like this

 

$.outputs[?(@.name=="EM_CLASSIFICATION")].value

View solution in original post

6 REPLIES 6

avatar
Master Collaborator

@Slade 

First of all I think there is a { missing at the begin of your JSON.

 

You can try here for example: http://jsonpath.herokuapp.com/

 

Basically it works with   $.outputs..name

 

avatar
Super Guru

As mentioned above, make sure you are sending full JSON Object.  Then in your EvaluateJsonPath processor click a + for each one you want to map to an attribute.  Then enter the key → values as below:

 

test1 → $.outputs.test1

test2 → $.outputs.test2

test3 → $.outputs.test3

test4 → $.outputs.test4

test5 → $.outputs.test5

test6 → $.outputs.test6


If this solution works please accept it as the solution to close the topic.

 

 

avatar
Explorer

Thanks for your help @stevenmatison  and @justenji . 

 

I have managed to get the below json attributes successfully  with simple $.AtrributeName

 

{
"test" : "7",
"dm0001al" : "-2",
"pp0406ln" : "5",
"pp0935cl" : "121",
"eq0001fl" : "-1",
"pp0406cl" : "1352",
"pp0934cc" : "-2",
"pp0026al" : "0",
"pp0035al" : "8",
"pp0901lb" : "-2",
"id" : 4,
"inputs" : [ {
"name" : "test",
"value" : 3
}, {
"name" : "dm0001al",
"value" : 1
}, {
"name" : "pp0406ln",
"value" : 1
}, {
"name" : "pp0935cl",
"value" : 1
}, {
"name" : "eq0001fl",
"value" : 1
}, {
"name" : "pp0406cl",
"value" : 1
}, {
"name" : "pp0934cc",
"value" : 1
}, {
"name" : "pp0026al",
"value" : 1
}, {
"name" : "pp0035al",
"value" : 1
}, {
"name" : "pp0901lb",
"value" : 1
} ]
}

 

But I am still struggling with the below one I tried a couple of tricks in EvalutuateIJson processor but still not values are assigning to attributes:

 

The content of my incoming flow is in full JSon and looks like the below. This is the full json

 

{
"outputs" : [ {
"name" : "EM_CLASSIFICATION",
"value" : "1"
}, {
"name" : "EM_EVENTPROBABILITY",
"value" : 0.9512272865085364
}, {
"name" : "EM_PROBABILITY",
"value" : 0.9512272865085364
}, {
"name" : "I_Responded",
"value" : "1"
}, {
"name" : "MSLR_woe",
"value" : 4.4659
}, {
"name" : "P_Responded0",
"value" : 0.048772713491463615
}, {
"name" : "P_Responded1",
"value" : 0.9512272865085364
}, {
"name" : "dm0001al_woe",
"value" : 0.853
}, {
"name" : "eq0001fl_woe",
"value" : 0.9315
}, {
"name" : "pp0026al_woe",
"value" : -0.2929
}, {
"name" : "pp0035al_woe",
"value" : 0.5839
}, {
"name" : "pp0406cl_woe",
"value" : 0.6062
}, {
"name" : "pp0406ln_woe",
"value" : 1.3878
}, {
"name" : "pp0901lb_woe",
"value" : 0.1952
}, {
"name" : "pp0934cc_woe",
"value" : -1.3256
}, {
"name" : "pp0935cl_woe",
"value" : -0.5781
} ]
}

 

I tried

 

$.outputs.pp0935cl_woe 

$.outputs..pp0935cl_woe

$.['pp0935cl_woe']

$.outputs.name.pp0935cl_woe

 

Still nothing coming through in the attributes.

 

Any suggestions?

 

Thanks

 

avatar
Super Guru

Try:

 

$.outputs.['EM_CLASSIFICATION']

 

that's $.mainobject.['array name'] to access the value for that outputs array item

 

Fun with Json...

avatar
Explorer

Tried it still nothing assigning

 

and tried all the below

 

$.['EM_CLASSIFICATION']

$.{EM_CLASSIFICATION}

$.{'EM_CLASSIFICATION'}

$.'{outputs.EM_CLASSIFICATION}'

$.outputs.{'EM_CLASSIFICATION'}

$.outputs.{EM_CLASSIFICATION}

$.outputs.{'name.EM_CLASSIFICATION'}

$.outputs.['..EM_CLASSIFICATION']

$.outputs.{'name'..'EM_CLASSIFICATION'}

 

might just plonk the full json in nvarchar field in sql and sql it out properly over their. 

avatar
Explorer

Ok so me and my mate figured it out :). Finally!

 

its like this

 

$.outputs[?(@.name=="EM_CLASSIFICATION")].value