Peter Cooper · May 20, 2018

JSON - is this a bug??

Hi All

I'm sharing this ticket just posted to wrc as I believe it is inconsistent behaviour. and other developers may trip over it....

<wrc ticket>

I have found something that appears to me to be inconsistent
Simple example

set x={"theValue":true} write x.theValue
this correctly converts true to 1

However if " (double quotes are placed around it
set x={"theValue":"true"} write x.theValue
it does not convert and displays the string "true"


</wrc ticket>


0 292
Discussion (7)2
Log in or sign up to continue

And it works exactly as it should be. I the first example it as a Boolean, and next as a string. What would you do if you would need literal "true", if it would converted to Boolean all the time?

Hi Dimitry

But still inconsistent
set x={"TheValue":"123"} write x.TheValue

Does not return a quoted string


Hi Demitri

It's me!!!!
I thought javascript was doing something different
if (oJSON.theValue) { write("hello") }

I *thought* that it was evaluating it as a boolean

It's not - the test is showing if it's defined

Learnt something today


Hey Herman

Glad to see that you are still around!!!!
Yup it's me - I was not understanding - see my reply above


Yes, it also works as expected, because

Write "123",456



Without any quotes, but it doesn't mean that there are no difference between "123" and just 123. You can see it if you would try to work with $zhex. Try by yourself

Write $zhex(32)

Write $zhex("32")

(still not herding sheep in Tuscany ;-))

How would you want to address a string with the value of "true" if there would be automatic translation to 1 ?