Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CJSON can not compare NULL #1580

Closed
petrkr opened this issue Nov 1, 2016 · 2 comments
Closed

CJSON can not compare NULL #1580

petrkr opened this issue Nov 1, 2016 · 2 comments

Comments

@petrkr
Copy link

petrkr commented Nov 1, 2016

Based on comment in source code https://github.com/nodemcu/nodemcu-firmware/blob/dev/app/modules/cjson.c
I trying compare NULL from JSON response, but I always getting "false" even using suggested compare with cjson.null one.

Expected behavior

return True

Actual behavior

returns false

Test code

json_null_test = cjson.decode('null')
print (json_null_test == cjson.null)
false

print (json_null_test)
userdata: 0x00000000

print (cjson.null)
nil

NodeMCU version

NodeMCU 1.5.4.1+petrkr build 20161101 powered by Lua 5.1.4 on SDK 1.5.4.1(39cb9a32) based on NodeMCU - branch dev commit f0780e3

Hardware

NodeMCU Devkit 1.0 with ESP-12

@petrkr
Copy link
Author

petrkr commented Dec 25, 2016

Found workaround for this issue:

cjson_null = cjson.decode('null') -- Define NULL object for compare 
json_null_test = cjson.decode('null') -- Parse real JSON
print (json_null_test == cjson_null) -- Compare with local variable
true

so I can use aswell in more complex JSON's

cjson_null = cjson.decode('null')
json_null_test = cjson.decode('{ "var1": "Test var string1", "null_var": null }')
print (json_null_test.null_var == cjson_null)
true

@pjsg
Copy link
Member

pjsg commented Jan 23, 2017

The new sjson module has an explicit sjson.NULL symbol which contains the null value in use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants