JSON get_num validation

Started by Rob, October 23, 2025, 12:24:34 PM

Previous topic - Next topic

Rob

How does GET_NUM(KEY$,validation) work if validation is on?

Do you get an ERROR 11 for a missing key?

Aaron Woodhouse

Hi Rob!

Using the get_num function normally without the no_validation flag will return an error 11 if the key doesn't exist. It does some checks within the object's keys to make sure your provided key will work.

If you use the no_validation flag, it will skip this initial key check, and instead return an error 23 since it can't actually find the value.

It will return an error either way, but the key validator would tell you the issue is due to the key, not that there is no value.
Software Developer
PVX Plus Technologies LTD.

martinp

Hey, I was having an issue with this but with GET_STR$

I see now if I pass GET_STR$(X$,1)  It returns null and no longer errors out. 

If I pass GET_STR$(X$,0) and X$ was not found in the data, the the error 11 isn't trapped

a serious error in: json.pvc 0484 error 11 results.  Shouldn't that  be trapped either way or did you want a hard error there?

Shouldn't the ,DOM=*NEXT   directive work there or?

Thanks for clarifying.

martinp

#3
I'm still genuinely concerned about this using the GET_STR$(X$)  and it erroring within pvx code (json.pvc) if the string is not found unless I use GET_STR$(X$,1) vs just GET_STR$(X$) ?

Mike King

Do you enable the 'NE' system parameter? 

The problem you are having sounds a lot like the error is being generated in the object and it may be assuming that the error will be cascaded back up the stack which it would be if the 'NE' parameter is not enabled.
Mike King
President - BBSysco Consulting - http://www.bbsysco.com
eMail: mike.king@bbsysco.com

Aaron Woodhouse

Hi Martin,

The error 11 was meant to be a hard error, but you can use something like a try-catch to handle values not being found. Alternatively, you may have better use with the no_validation flag, since you can just compare the return value.

DOM=*next is meant for use with indexed data, but with associative arrays, and hence JSON, we store data as key-value pairs, which are not indexable. There are JSON Object functions that actually allow you to index it, but it should be avoided.

Like Mike mentioned; depending on what you are doing you could alternatively disable the 'NE' parameter.
Software Developer
PVX Plus Technologies LTD.