Code Monkey home page Code Monkey logo

Comments (9)

linuxha avatar linuxha commented on September 26, 2024

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.

colinl avatar colinl commented on September 26, 2024

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.

linuxha avatar linuxha commented on September 26, 2024

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.

colinl avatar colinl commented on September 26, 2024

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.

linuxha avatar linuxha commented on September 26, 2024

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.

colinl avatar colinl commented on September 26, 2024

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.

linuxha avatar linuxha commented on September 26, 2024

Thanks for the information, I'll read that and get the readme corrected. :-)

This won't be easy.

from node-red-contrib-mytimeout.

linuxha avatar linuxha commented on September 26, 2024

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.

linuxha avatar linuxha commented on September 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.