X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fcommon%2Fcount_json_elements.py;h=65e32c7efdcb0fe56f2e2cc817ddbd4888658ca1;hb=1b732d17463fad74721391b3a87a2a12172da63c;hp=936e3f8a31b2b3b309cb4fd5f91b2dd622d32f19;hpb=7a7a13a47eeebf9a61fa84d14af59b1cbe1598bc;p=nonrtric.git diff --git a/test/common/count_json_elements.py b/test/common/count_json_elements.py index 936e3f8a..65e32c7e 100644 --- a/test/common/count_json_elements.py +++ b/test/common/count_json_elements.py @@ -20,16 +20,24 @@ import json import sys # Print the length of json array, -1 will be printed in any problem is encountered +# Assumes the top level json is an array. +# If not (and the number of keys on top level is 1) then assumes that key contains the array. +arr_len=-1 try: with open(sys.argv[1]) as json_file: jsonarray = json.load(json_file) - if isinstance(jsonarray, list): - print(len(jsonarray)) - else: - print(-1) + arr_len=len(jsonarray) + elif isinstance(jsonarray, dict) and len(jsonarray) == 1: + key=next(iter(jsonarray)) + jsonarray=jsonarray[key] + if isinstance(jsonarray, list): + arr_len = len(jsonarray) except Exception as e: - print(-1) + print(arr_len) + sys.exit() + +print(arr_len) sys.exit() \ No newline at end of file