Extract specific values from nested JSOn output

uiautomation
studio
api

#1

Hello All,

I need to get specific values from output json. Like from below example I want to get value of ‘phyMarks’.

{
    "data": {
        "accounts": {
            "studentId": "2345",
            "schoolId": "034234",
            "SchoolName": "ABC",
            "schoolCode": "MU123",
            "State": "MH",
            "studentCount": 1234
        },
        "transactionSummary": [
            {
                "calDate": "2018-05-25T00:00:00.000",
                "phyMarks": 65,
                "choiceLanguage": "MAR",
                "studentBatch": "C",
                "studentId": 1234
            },
            {
               
                "calDate": "2018-05-25T00:00:00.000",
                "phyMarks": 75,
                "choiceLanguage": "HIN",
                "studentBatch": "D",
                "studentId": 342
            }
        ]
    },
    "status": {
        "isSuccess": true,
        "message": "SUCCESS",
        "statusCode": "0"
    }
}

Any help would be appreciated.
Thanks


#2

Refer this


@Rahul_S


#3

@Rahul_S

First Read the text and serialise it to a JObject Let us take it as obj
Create a List of strings List A

 ListA= (From p In obj(“data”)(“transactionsummary”)
            Select Convert.ToString(p("phyMarks")).ToList 

Now List A will contain the values of PhyMarks.

Regards,
Mahesh


#4

Thanks for reply Shreekanth

I am trying to save my output json in one variable and then I am applying the given solution.

But I am getting following error:

“For each : Object reference not set to an instance of an object.”

Thanks


#5

#7

@Rahul_S

No actually now I cant send the xaml. try on your own, If you find any difficulties. please ask i will try to help you.

Regard,
Mahesh


#9

@Rahul_S
where you have stucked.
first read the notepas by using readtextfile activity.
then use serialise jason activity the store it in a jobject variable type.

then use the Linq which i have given to you in assign activity.

Regards,
Mahesh


#10

Hi

I am not storing JSON output to any file.

I am storing JSON to string variable and then trying to perform.

Getting error “Object Reference Not set to Object.”

Please can you send one sample example?

That will really help me.


#11

@Rahul_S

Read the text file and store it in a string variable, then Parse the string to a Jobject then use the Linq to get the required values

I have attached the xaml for your reference.

JSON.zip (2.8 KB)

Regards,
Mahesh


#12

@MAHESH1

Thanks a lot Mahesh.