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 decode limited to 250 characters #1494

Closed
Jonathan411 opened this issue Sep 7, 2016 · 3 comments
Closed

CJSON decode limited to 250 characters #1494

Jonathan411 opened this issue Sep 7, 2016 · 3 comments

Comments

@Jonathan411
Copy link

Jonathan411 commented Sep 7, 2016

A json string with 250 characters or less decodes correctly, but if the string of json data is 251 characters or more in length then an error is raised: LUA interpreter error detected!

The following code works:

jstr='{"aa":"1","bb":"2","cc":"3","dd":"4","ee":"5","ff":"6","gg":"7","hh":"8","ii":"9","jj":"10","kk":"11","ll":"12","mm":"13","nn":"14","oo":"15","pp":"16","qq":"17","rr":"18","ss":"19","tt":"20","uu":"21","vv":"22","w":"23","x":"24","y":"25","z":"26"}'
for k,v in pairs(cjson.decode(jstr)) do print(k,v) end

The following code generates an error (one additional "w" character):

jstr='{"aa":"1","bb":"2","cc":"3","dd":"4","ee":"5","ff":"6","gg":"7","hh":"8","ii":"9","jj":"10","kk":"11","ll":"12","mm":"13","nn":"14","oo":"15","pp":"16","qq":"17","rr":"18","ss":"19","tt":"20","uu":"21","vv":"22","ww":"23","x":"24","y":"25","z":"26"}'
for k,v in pairs(cjson.decode(jstr)) do print(k,v) end

I also tested a json string that contained a single key/value pair. If the combined length of the key/value pair exceeds 250 characters the same error is raised.

I am using the following:

NodeMCU custom build by frightanic.com
branch: dev
commit: 3109497
SSL: true
modules: cjson,file,gpio,http,net,node,tmr,uart,wifi
build built on: 2016-09-06 13:26
powered by Lua 5.1.4 on SDK 1.5.4.1(39cb9a32)

Is the 250 character limit a feature or a bug? I couldn't find any documentation which mentions a limit on the size of the json input string.

@luismfonseca
Copy link
Contributor

This doesn't seem to be a limitation of the cjson module, but rather the max length that Lua String can be declared (without concatenation).

The following code works:

jstr = '"aa":"1","bb":"2","cc":"3","dd":"4","ee":"5","ff":"6","gg":"7","hh":"8","ii":"9","jj":"10","kk":"11","ll":"12","mm":"13","nn":"14","oo":"15","pp":"16","qq":"17","rr":"18","ss":"19","tt":"20","uu":"21","vv":"22","w":"23","x":"24","y":"25","z":"26"'

jstr = '{'..jstr..',"xyz":"1231231231231"}'

print(string.len(jstr) .. '\n') -- 270

for k,v in pairs(cjson.decode(jstr)) do print(k,v) end

@Jonathan411
Copy link
Author

Not a NodeMCU issue then. Thanks.

@luismfonseca
Copy link
Contributor

Well, I think it sorta is, in the sense that the 250 is the limit configured in NodeMCU...

If you run Lua on a computer, it doesn't have this limitation. Well, at least not 250. So I suppose that this was mostly a decision based on memory constraints.

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

2 participants