-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Add support for streaming JSON encoder/decoder #1755
Conversation
Overflows iROM... again. Hmmm... |
I think that we are getting close to where we can't increase the irom any more.... We have enough modules that they will not be able to be built at the same time! |
Safe size for iROM is |
docs/en/modules/sjson.md
Outdated
|
||
- `setpath({}, {})` the `table` argument is the object that will correspond with the value of the JSON object. | ||
- `setpath({}, {"foo"})` the `table` argument is the object that will correspond with the value of the outer JSON array. | ||
- `setpath({}, {"foo", 3})` the `table` argument is the object that will correspond to the empty inner JSON array. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the intended use of setpath
? The first argument appears to always be an empty table. Can I do something interesting with that table? Can I return something from the setpath
call to indicate that I don't want this piece decoded/kept?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added documentation to describe it better. I'm definitely open to making this a checkpath method instead that returns true if you want to keep the element, and false if not. Default would be true if the checkpath method was not supplied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't really thought through what the likely usecases are here, but I suspect a checkpath
would be more readily understood. Or it could be that we just need some more docs or examples?
- `string` the next piece of JSON encoded data | ||
|
||
####Returns | ||
The constructed lua object or `nil` if the decode is not yet complete. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is the same value as from sjson.decoder:result()
then? Do we really want both of these then? It seems redundant at first glance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was a way to signal that decode is complete (if that is of interest). You want the result method so that you can always get the final result.
Then why don't we use that value - at least during PR builds? |
I changed the |
Do you really want to maintain two JSON modules? If it's a drop-in replacement for |
I'd like to replace CJSON entirely. I didn't want to call this new code |
@@ -5,7 +5,7 @@ MEMORY | |||
dport0_0_seg : org = 0x3FF00000, len = 0x10 | |||
dram0_0_seg : org = 0x3FFE8000, len = 0x14000 | |||
iram1_0_seg : org = 0x40100000, len = 0x8000 | |||
irom0_0_seg : org = 0x40210000, len = 0xD0000 | |||
irom0_0_seg : org = 0x40210000, len = 0xE0000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This value is also good enough to build #1231, I just tested. So, if we merge this one first we can finally merge that one as well.
Even though JSON support is quite popular (among top-10 non-default modules) I wouldn't do that and introduce a breaking change instead. Anyone building a new firmware will notice that CJSON is gone and will check the documentation. Of course the release notes will also state this but who reads release notes anyway. |
Oh, and ideally you keep |
This removes cjson (but leaves the documentation that now just points to sjson). Examples updated. |
Sorry for the delay, I had it in my head this had already been merged. Many thanks @pjsg, I won't miss the cjson mess :) |
hi, I'm write a article about this module。 I have some difficulty understanding metatable when I use sjson.decoder()。 http://nodemcu.readthedocs.io only one example。Can anyone give more than one example? and this is my articles http://www.jianshu.com/nb/7000517 ,Chinese Only thanks |
The idea is to allow you to decode large JSON responses without needing to get the entire response into memory at once. One of the motivations that I had was to be able to store a nodemcu lua project in GIT and have the nodemcu auto-provision itself and auto-update itself. I haven't actually done this yet, but it is not that difficult. The steps are:
[Actually, now I read it, this is basically the example] There are a bunch of JSON endpoints which return more data than the client actually wants. This allows that filtering. I'll dig up some more examples. What aspect are you interested in? |
such as a weather @pjsg . Usually, weather api return json, and I need some infomation like temperature |
here is a free weater api http model can't deal it, How can I do? |
I wrote this example piece of code that just gets the weather in London. It actually doesn't query the live API, but uses a sample data blob so it should print out "Drizzle" The Does this help?
|
yes, thinks @pjsg |
@pjsg Recently, I was looking at the Travis CI build log and saw a couple of warnings |
I can confirm that I too am seeing these undefined symbol warnings. I'm surprised that they're only warnings, I'm sure they used to be errors. |
Replaces the problematic cjson module.
The docs explain that the __newindex method can be used to filter what goes into the new table by checking the key value and skipping the 'rawset' function.
This is the code i have so far But when I try to recall or iterate through decode:result() it turns out to be nil. What am I missing here? |
Please do not post on closed items. |
Fixes #1666 (partially).
dev
branch rather than formaster
.docs/en/*
.This makes use of the jsonsl package (which is under a very liberal license). It wraps it in a layer to interface to lua for decoding json strings. There is also an incremental encoder.
The decoder can call out to lua code during the decoding to give the lua full control over which parts of the data structure should be retained (or handled inline).
It does provide an API which is compatible with
cjson
.This is the first step to resolve the issue #1666. The next is to deal with the http client....