How to get Json Array values from json format?

Hello All,

I have json data and where have array values.

Example:-

{
“Test111”: {
“Test222”: [
{
“name”: “Test Data123”,
“effectiveDate”: “2021-09-27T04:01:00Z”,
“amt”: “$10/$200”,
“premium”: {
“amount”: 0,
“currency”: “usd”
},
“code”: “sfdsfdf”
},
{
“name”: “Test Data123”,
“effectiveDate”: “2021-09-27T04:01:00Z”,
“amt”: “$50”,
“premium”: {
“amount”: 0,
“currency”: “usd”
},
“code”: “ewr”,
}]
}

Note:- THIS IS DUMMY DATA.

So I have json like above mention. Where first read “Test111” then “Test222” and then get “name” “amt”

SO basically I need to get data from name and amt.

I have tried to use Desirable JsonArray, but it is giving error. and also tried with JsonString to parse to convert jarray.

Any one suggest here, what can do with this??

1 Like

Hi @shuklarchana001,

Can you please show what error you are getting and the approach so that a solution in that can be provided.

Thanks

use in for each loop CType(jsonObject(“Test111”)(“Test222”),JArray)

Error:- Object reference not set to an instance of an object.

Hi @shuklarchana001,

Please, take a look at the attached file

Main.xaml (6.3 KB)

If this solves your problem, kindly mark this post as solution to close this topic.

If you need extra help and/or have any question, please let me know :slight_smile:

Thanks!

I have tried same but still given same error as earlier I have mention error

1 Like

@shuklarchana001

What’s the error?

Here is working as expected.

Error:- Object reference not set to an instance of an object.

1 Like

Are you using the json below?

If so and you use the attached file I sent you, it will work properly.

If you are using the real json, I would need to see it (be careful with private data) to identify the error, if possible.

{
"Test111": {
"Test222": [
{
"name": "Test Data123",
"effectiveDate": "2021-09-27T04:01:00Z",
"amt": "$10/$200",
"premium": {
"amount": 0,
"currency": "usd"
},
"code": "sfdsfdf"
},
{
"name": "Test Data123",
"effectiveDate": "2021-09-27T04:01:00Z",
"amt": "$50",
"premium": {
"amount": 0,
"currency": "usd"
},
"code": "ewr",
}]
}

I am using json but same getting error.

I need json array values from json data

1 Like

@shuklarchana001,

Sorry, are you using the real json or the fake one?

real one in my scenario

1 Like

@shuklarchana001

Ok Ok.

Could you send a screenshot of the activity that throws the exception?


image

In this case, not entering in loop , it just skip loop and move

1 Like

Hi @shuklarchana001

Got it.

I believe some of the items don’t have those properties. So when you try to access documents, for example, it will return null. Then, you try to access the currentTermDocuments of a null, it will throw that exception.

So you need to verify before using an if.

Something like this:

yourItem("result") IsNot Nothing AndAlso yourItem("result")("policy") isNot Nothing AndAlso yourItem("result")("policy")("documents") IsNot Nothing AndAlso yourItem("result")("policy")("documents")("currentTermDocuments") IsNot Nothing

Or you can use nested ifs checking one by one and log something in each else branch if you want

If yourItem(“result”) IsNot Nothing

If yourItem(“result”)(“policy”) isNot Nothing

If yourItem(“result”)(“policy”)(“documents”) IsNot Nothing

If yourItem(“result”)(“policy”)(“documents”)(“currentTermDocuments”) IsNot Nothing

1 Like

@shuklarchana001,

If that solves your problem, let me know and kindly mark the most useful post as solution to close this topic.

If you need extra help and/or have any question, please let me know :slight_smile:

Thanks!

For Each: Unable to cast object of type ‘Newtonsoft.Json.Linq.JProperty’ to type ‘Newtonsoft.Json.Linq.JObject’.

1 Like

@shuklarchana001

Could you send me part of your real json? Just replace private data by fake one, but keep the real structure please

Hi @shuklarchana001

Considering the json below, this code works as expected:
Main.xaml (6.8 KB)

{
	"result": {
		"policy": {
			"documents": {
				"currentTermDocuments": [
					{
						"name": "Test Data123",
						"effectiveDate": "2021-09-27T04:01:00Z",
						"amt": "$10/$200",
						"premium": {
							"amount": 0,
							"currency": "usd"
						},
						"code": "sfdsfdf"
					},
					{
						"name": "Test Data123",
						"effectiveDate": "2021-09-27T04:01:00Z",
						"amt": "$50",
						"premium": {
							"amount": 0,
							"currency": "usd"
						},
						"code": "ewr",
					}
				]
			}
		}
	}
}
4 Likes

@gustavo.cervelin Its is working now. And thank you so much for your time and hard work. :slight_smile:

1 Like