Comments (9)
Save your sanity and stick with JSON objects. I do try to handle JSON string that can be decoded to objects but I don't know if I cover all possible implementations of it.
Example:
{"payload":"{ \"payload\":\"on\",\"timeout\":6,\"warning\":0}","qos":0}
becomes:
{ "payload":"on","timeout":6,"warning":0}
But if it arrives in another format I'm not sure I can handle it correctly. If you mean something else please provide an example. Actually it would be a good idea to provide and example anyway.
I recall strings to object giving me nightmares figuring out and testing.
from node-red-contrib-mytimeout.
I am confused by your use of the term "JSON object". JSON is a method of encoding javascript objects as strings (https://en.wikipedia.org/wiki/JSON), so there is not really any such thing as a JSON object. There are javascript objects and there are JSON strings. JSON is always a string, which represents a javascript object. Am I right in thinking that when you say JSON object you actually mean javascript objects?
from node-red-contrib-mytimeout.
Sorry, I don't write as much code as I used to (Python for automation, C, Asm). The rest is hobby so I'm not up on the correct terminology (I do QA and know correct terminology is important). I also see I messed up the quoting above. What I meant by a JSON string is a string that contains escaped JSON (it has not been parsed yet): Example:
{"payload":"{ \"payload\":\"on\",\"timeout\":6,\"warning\":0}","qos":0} // the payload contains a string
Parsed becomes:
{ "payload":"on","timeout":6,"warning":0 } // This is JSON, I call it a JSON object
I've been calling what the first payload returns a 'JSON string' and the second a JSON object. Technically it's all strings but when you query (typeof(msg.payload) it from Javascript it's a string and an object
from node-red-contrib-mytimeout.
If, for example, in a function node I put
msg.payload = {"payload":"on", "timeout":6, "warning":0 }
return msg
Then in msg.payload is a javascript object, not a JSON object. So to get back to my original question, can I feed the output of the above function into your node and expect it to work?
from node-red-contrib-mytimeout.
msg.payload = {"payload":"on", "timeout":6, "warning":0 } return msg
Yes, that will work.
I basically get this from an inject (payload {} "payload":"on","timeout":30} ):
{"_msgid":"7693409.f2669c","topic":"","payload":{"payload":"on","timeout":30}}
That's from a debug node set to the complete msg object. Note the lack of the warning means it takes the default values. Same would apply to the timeout. I think I treat a lack of a payload as an on message. The original timer that Pete wrote just send something to the time to 'tickle' it on.
Sorry for any confusion.
from node-red-contrib-mytimeout.
Thanks for clarifying that the node accepts Javascript objects rather than JSON (string). Could I suggest that you remove references to JSON from the readme as it causes confusion among readers who think that it is necessary to pass in a string rather than just ordinary javascript objects with attributes. See this thread on the node-red forum for example where the poster was having difficulty trying to construct a string.
https://discourse.nodered.org/t/need-some-help-with-a-varable-json/14210
from node-red-contrib-mytimeout.
Thanks for the information, I'll read that and get the readme corrected. :-)
This won't be easy.
from node-red-contrib-mytimeout.
Colin thanks for the information and setting me straight. I've made a first attempt at the corrections. I hope this is better. I still need to further work so that it is less confusing.
Oh, having a bit of trouble with github push (dang key issue, I'll resolve that this weekend). The NPM publish worked better.
from node-red-contrib-mytimeout.
I'm going to close this but I still have additional work on the documentation to do.
from node-red-contrib-mytimeout.
Related Issues (20)
- Timer does not stop for FLOAT timeout values HOT 3
- "TypeError: node.warn is not a function" HOT 4
- Time remaining (Output 2) is not in msg.payload HOT 1
- Pause? HOT 6
- L495: newMsg(inMsg): RangeError: Maximum call stack size exceeded HOT 13
- Output Topic - not coming out HOT 5
- First countdown msg is a string ! HOT 7
- Run different instances of timer based on msg.topic HOT 3
- Feature Request: Allow the Timer On Payload HOT 1
- Feature Request: Allow the "Timer On Payload" to work like the "Warning state payload" HOT 3
- A msg.warning of 0 doesn't override the GUI setting to cancel sending a warning message HOT 3
- Warning output doesn't contain extra attributes like the on and off messages do.
- Warning sent when setting countdown to low value eg. `3` and warning param to 0 in GUI HOT 4
- Topic Using Mustache HOT 10
- Add topic to 2nd output HOT 5
- Tick interval HOT 4
- strange behaviour, does not turn off , or even turns on instead HOT 3
- unwanted starting of countdown HOT 6
- The workspace contains some nodes that are not properly configured ... HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-red-contrib-mytimeout.