Api - Json Problema al contar y verificar los elementos

Tengo el siguiente problema, tengo un json y necesito verificar la cantidad de elementos que tengan una característica, en este caso quiero obtener y verificar la cantidad de categorías, en este caso lo que espero es que la cantidad sea 1, pero la herramienta me dice que la cantidad es igual a 0, alguien me diría en que le estoy errando?

{
  "Categories":[
  ],
  "Id": 1
}

Hi,

Sorry that I do not know Spanish. Using Translate, I understand your question is that:

With the mentioned Json, you want to check the number of categories and get 1 instead of 0 as it returned.

I think the format of your Json has told us already that the number of categories is 0. I cannot know why you want it to be 1. Or can you please post it in English for better understand?

Hi Elly_Tran, the method I’m using returns an object with its characteristics, I understand that since it’s an object, the characteristic must count as 1, maybe I’m wrong. I am new to api automation, I have another method that returns a json as follows

[{
  "idCountry": 1,
  "Country" : "Argentina"
}]

And when using the count method, it returns 1

While in the following case:

{
  "idCountry": 1,
  "Country" : "Argentina"
}

The count method returns 0

I don’t understand what is the difference

Please show your code; how does it call “the count method”?

I ask you this becase I don’t see what is “the count method” you mean.

That would be the case that I have


def response = WS.sendRequest(findTestObject('Object'))


Json response
{
  "Categories":[
  ],
  "Id": 1
}


def elementsCount = WS.getElementsCount(response, 'Categories')
println("Number of items = " + elementsCount)

Number of items = 0

Your code is running just right. The elementsCount will have the value 0. No doubt.

I wonder why you are not happy to see 0.

Please describe your thought how your code should work. … This would reveal what you do not understand yet.

The above is an array of objects.

{
  "idCountry": 1,
  "Country" : "Argentina"
}

The above is just an object.

The language barrier seems to be a major blocker here, so I am trying to limit my reply to 'geek language"

That is, if I only have one object, and I refer to the attribute of the object, does it count 0?

up to now you posted 3 versions:

{
  "Categories":[
  ],
  "Id": 1
}
[{
  "idCountry": 1,
  "Country" : "Argentina"
}]
{
  "idCountry": 1,
  "Country" : "Argentina"
}

Each one is different.
Do you really need our help?
Than, kindly do some efforts to explain your issue better.
We are not here to do magic.

I’m sorry if I bothered you, I didn’t mean to.

The first two were examples.

The third was the actual case.

Anyway I already understood the problem with the previous answer you gave me

You don’t bothered us.
Glad to hear you understood where the difference is!