Accessing values from a Json

Hello everyone,

I’m having trouble accessing the values ​​of a Json. I’ve tried several ways
Array
item (“name”). tostring
item.selettoken

Nothing works.
Can someone help me


JObject(2)
{
JProperty(1)
{
JArray(359)
{
JObject(9)
{
JProperty(1)
{
[null]
},
JProperty(1)
{
[00.01.001.001 - FM2C - CORPORATIVO - SP - MATRIZ]
},
JProperty(1)
{
[null]
},
JProperty(1)
{
[null]
},
JProperty(1)
{
[9600181]
},
JProperty(1)
{
[0001001001]
},
JProperty(1)
{
[00.01.001.001]
},
JProperty(1)
{
[null]
},
JProperty(1)
{
[vicente.sousa@fm2c.com.br]
}
},
JObject(9)
{
JProperty(1)
{
[null]
},
JProperty(1)
{
[00.01.001.111 - FM2C - DESP. TRANSITORIA - GESTAO - 01/2020]
},
JProperty(1)
{
[null]
},
JProperty(1)
{
[null]
},
-------------------------------------------------------- Json
{

"content": [

    {

        "EMAIL_COORDENADOR": "null",

        "DESCRI": "00.01.001.001 - FM2C - CORPORATIVO - SP - MATRIZ",

        "APROV_GERENTE": "null",

        "EMAIL_GERENTE": "null",

        "APROV_DIRETOR": "9600181",

        "CCUSTO": "0001001001",

        "UN": "00.01.001.001",

        "APROV_COORDENADOR": "null",

        "EMAIL_DIRETOR": "vicente.sousa@fm2c.com.br"

    },

I need to access o CCUSTO

errors presented

image
Write Line: Cannot access child value on Newtonsoft.Json.Linq.JProperty.

and

image

and

Deserialize JSON Array: Error reading JArray from JsonReader. Path ‘’, line 0, position 0.

Is this the Whole Json Content?

Hi @KMota

try using both of this below ways

  1. JsonObjVariable(“CCUSTO”).ToString outside foreach activity within messagebox or writeline activity

OR

  1. JsonObjVariable(“content”)(“CCUSTO”).ToString outside foreach activity within messagebox or writeline activity

Where JsonObjVariable is the output variable you got from Deserialize JSON Activity

Mark as solution and like it if this help you :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

1 Like

Yes,

that’s right

Hi @Pratik_Wavhal

in the first case it presents all the Json, it works, but I only need the CCUSTO
image

in the second case it gave this error
image

resulte(“content”)(0)(“CCUSTO”).ToString

I put it like this, I think it was, I just need to set the index

@KMota Check this Workflow :
JsonValueExtraction.zip (2.5 KB)

2 Likes

YESSSSS,

It worked, it worked!

Thank you
:smiley:

1 Like

@KMota You can also Access it in this way Without For Each.

KMota

2 Likes

thanks :slight_smile:

1 Like

Hi,
image

after running several CCUSTO he gave this error, can you tell me about something

@KMota Is the Value Present in it? It might be because the value is Empty or not present in the Json

could it be, in this case, that there are no more CCUSTO to seek?

In this case, as there is no more CCUSTO, how can I escape this error and continue the application

@KMota Depending on whether CCUSTO is present or not, you can use this method :

I understand, it may really happen that some case comes without the COST, but it gave this error

image

@KMota ContainsKey has a Wrong Spelling :sweat_smile:

:sweat_smile: :sweat_smile: :sweat_smile:

forget it kkkkkkk

1 Like

that’s right, he is giving an error, because a call arrives that does not have the COST, but still presents the error

I tried like that too,
image

image

This didn’t Solve it?

no, when it arrives at the index that returns null on the COST it gives the error of an unreferenced object.
then I tried it the other way, but it also didn’t work, I’ll try to put it in a try catch, but I still don’t know how to escape this error. In the API it really arrives in that call and returns NULL to the COST,
he would have to move on to the next

@KMota The ContainsKey method should have escaped the Error actually :sweat_smile: . I tested the same workflow, by editing the Json Value, By Removing the Key “CCUSTO” and making the value as Empty. It didn’t throw an error using that If Statement.