0

I have problem to get size items of array. Function of jsonPath "length()" not implemented in g1ant, because throwing exception "Array index expected". Below is sample in g1ant script for test.

addon core version 4.103.0.0
addon language version 4.104.0.0
♥jsonImage = ⟦json⟧‴{ "book" : [ { "name" : "Bambi"} , { "name" : "Cinderella" } ] }‴
♥aaa = ♥jsonImage⟦$.book.length()⟧
dialog ♥aaa

Are there other solutions related to the length of the array?

1 Answers1

2

It's not possible to get the number of json array elements in the way that you are trying. G1ANT is using Newtonsoft.Json library for selecting json tokens where they don't allow expressions like .length() as you can read here.

Here's how you can workaround this issue.

♥jsonImage = ⟦json⟧‴{ "book" : [ { "name" : "Bambi"} , { "name" : "Cinderella" } ] }‴

♥jsonArrLength = 0
♥hasExceptionOccurred = false

while ⊂!♥hasExceptionOccurred⊃
    try errorcall NoMoreElements
        ♥test = ♥jsonImage⟦book[♥jsonArrLength]⟧
        ♥jsonArrLength = ♥jsonArrLength + 1
    end try
end while

dialog ♥jsonArrLength

procedure NoMoreElements
    ♥hasExceptionOccurred = true
end procedure
Wiktoria Prusik
  • 840
  • 4
  • 15