LibreCat / Catmandu

Catmandu - a data processing toolkit
https://librecat.org
175 stars 31 forks source link

is_string conditional and number strings #393

Open TobiasNx opened 2 years ago

TobiasNx commented 2 years ago
{ "number" : 123 }
{ "number" : "123"}
if is_string("number")
    add_field("test","true")
end

The is_string conditional is not recognizing the second variation of numbers as string. Is this by intention, if so this should be documented. How is it possible to check if a number string is a string?

phochste commented 1 year ago

Hi, this is not the intention. Can you provide some context on the version of Catmandu?

With

if is_string(test)
    add_field(ok,0)
else
    add_field(ok,1)
end

and Catmandu 1.2016 this works for me:

$ echo '{"test":"123"}' | catmandu convert --fix ~/Desktop/TMP/brol.fix
[{"test":"123","ok":"1"}]
$ echo '{"test":123}' | catmandu convert --fix ~/Desktop/TMP/brol.fix 
[{"ok":"1","test":123}]
$ echo '{"test":"1a23"}' | catmandu convert --fix ~/Desktop/TMP/brol.fix
[{"test":"1a23","ok":"0"}]