Problem using size() to determine length of a JSON array


#1

1) Give a description of the problem
I want to determine the length of a JSON array but the result is not as I expect.

2) What is the expected behaviour?
I expected it to return the number of items in the array. I am expecting a size of 2 in my example.

3) What is happening/not happening?
It is returning the number of key/value pairs in all of the array items. I am getting a size of 5.

**4) Post a Green Snapshot of the piston![image|45x37]![image|690x253]

5) Attach logs after turning logging level to Full
1/29/2023, 3:47:58 PM +592ms
+3ms ╔Received event [Hub Me].test = 1675025278592 with a delay of 0ms, canQueue: true, calledMyself: false
+8ms ║RunTime initialize > 7 LockT > 1ms > r9T > 1ms > pistonT > 0ms (first state access 2 m:5 4 3)
+10ms ║Runtime (5905 bytes) initialized in 1ms (v0.3.114.20230113_HE)
+11ms ║╔Execution stage started
+15ms ║║Executed virtual command parseJson (1ms)
+18ms ║║{“family”:[{“firstName”:“Barb”,“lastName”:“Wise”},{“firstName”:“John”,“middleInitial”:“V”,“lastName”:“Yang”}]}
+20ms ║║Executed virtual command log (2ms)
+24ms ║║5
+25ms ║║Executed virtual command log (1ms)
+27ms ║╚Execution stage complete. (16ms)
+29ms ╚Event processed successfully (26ms)


#2

Does this help?


#3

Yes, this solves my problem. I changed my code to $json.family.length and got the expected result.