Working With JSON Data in Node Red

Поделиться
HTML-код
  • Опубликовано: 11 окт 2024
  • JSON is popular format for encoding data sent over the Internet, and also for data stored in files.
    In this video tutorial we take a more detailed look at node-red and JSON data.
    We look at the JSON.parse() and JSON.stringify() functions which you can use in the function node and also the JSON node which does the encoding and decoding for you.
    We look at decoding JSON data using the JSON expression editor in the change node.
    You will learn how to extract data from JSON strings,payload and message objects using the function node and the change node and the expression editor and jsonata.
    We also look at working through JSON data using the node command line.
    This is very useful when troubleshooting JSON data problems.
    You will also encounter errors when decoding JSON data we look at creating JSON data using the inject node and what the message Unexpected token in JSON at position 0 means
    Tutorial on website
    www.steves-internet-guide.com/working-with-json-data-node-red/
    Flow used in video
    stevesnoderedg...
    Related videos
    Publish JSON Data over MQTT with Node-Red
    • Publish JSON Data over...
    Receive JSON Data Over MQTT with Node-Red
    • Receive JSON Data Over...
    Node-Red -Guide to Using The CSV Node
    • Node-Red -Guide to Usi...
    How to Log MQTT Sensor Data in Node-Red
    • How to Log MQTT Sensor...
    Have a question Use the comments or if you want help then use
    www.steves-inte...
    If you find these videos useful then you might want to consider buying me a coffee
    www.paypal.me/...

Комментарии • 47

  • @jarchdm
    @jarchdm 4 года назад +2

    Finally I'm beginning to understand this. This was by far the clearest and most practical explanation of the object I have seen. Many thanks for making this.

  • @wingman1392
    @wingman1392 4 года назад

    Thank, thank you, thank you Steve. After 30+ years of fog of non tech work, I am trying to get back into making stuff. I have set my goal as a small monitoring system, weather, water butt levels, nothing too complicated. I have been going spare searching, and watch video, and not understanding. You have opened my eyes in this video. Thank you. I was contemplating scrapping the idea, and going old school with 8085 and machine code.

  • @mickc6700
    @mickc6700 2 года назад

    Excellent video and very clear. There are so many useful topics here, some are worth their own video, especially that last one.

  • @qusaiamer6853
    @qusaiamer6853 2 года назад

    Thank you! very helpful after being stuck for nearly two hours :)

  • @mikrom
    @mikrom 5 лет назад

    thank you man! I just fall into NodeRED and your tutorials are amazing. I watched them all in last few days with man flu :)
    BTW your voice sounds very similar to my UK colleague. Stratford Upon Avon, Redditch area. Thanks for your work and I am looking forward for next video.

  • @asiw
    @asiw 5 лет назад

    Thanks for providing a very helpful examination of JSON uses and techniques.

  • @daveacorn782
    @daveacorn782 5 лет назад +1

    Great video Steve, this has helped answer a lot of my questions I was having. Thanks!!

  • @thegeterrdone
    @thegeterrdone 5 лет назад +1

    Thank you for this amazing video:)

  • @The_Unobtainium
    @The_Unobtainium 3 года назад

    You're doing great job, Steve! Thank you

  • @CreatureArtworks
    @CreatureArtworks 4 года назад

    Very nice video, helped me grately to understand JSON

  • @Venkel08
    @Venkel08 4 года назад

    I have learned a lot. Thank you very much

  • @pivoglotik
    @pivoglotik 4 года назад

    Thanks. Very useful video!

  • @dion4894
    @dion4894 2 года назад +1

    I get the error 'Invalid conversion from system.string to json.linq.object'. How do i resolve this? i can't pass a variable back to my robot now..

    • @stevecope
      @stevecope  2 года назад

      What are you trying to do JSON to Javascript or vice versa. can you show me the data.
      rgds
      steve

    • @dion4894
      @dion4894 2 года назад

      @@stevecope i get output from an API key from google maps. I only extract the distance and duration and want to pass that back to my robot in OpenRPA as variables. Everything works but it the robot won't receive anything because of that error. Maybe it has to do with creating a variable in NodeRed that has dynamic value (depending on which adress and destination the API key receives)?

    • @stevecope
      @stevecope  2 года назад

      @@dion4894 Can you send me a sample of the raw data you get and what values you want and I will take a look.

  • @lotlottol8747
    @lotlottol8747 3 года назад

    Спасибо !

  • @guicmbh
    @guicmbh 5 лет назад +1

    What is the node.log(type of p) statement you seem to always skip explaining it when going through the JSON in the function node. Why is it? Btw thanks for the good work

    • @stevecope
      @stevecope  5 лет назад +4

      The node.log() sends messages to the console. It is used for debugging. It is like the Python print statement.

  • @abcd-yg2rx
    @abcd-yg2rx 4 года назад

    Why doesn't node red read the Arduino JSON ? I think it s a JSONformat that is specif to Arduino. Instead if in Arduino I write a JSON string (that can be parsed to make it become prettified) with sprintf(so In this case I think it makes a string more specific to the language C) , node red can read it correctly.

  • @mateuszmalik1531
    @mateuszmalik1531 2 года назад

    Is there any easier and faster way to inject dynamic data into JSON object or is it always necessary to use a function and dynamically create an object?

    • @stevecope
      @stevecope  2 года назад

      Th e change node allows you to modify an object but it isn't dynamic in that it will do the same each time.

  • @biogasbrasil
    @biogasbrasil 4 года назад

    Great Video Steve! I am just starting to work with Node Red. I try to follow the steps but i was wondering what would come out if you would have put “s.payload.Time” with T instead of t at 19:37?

    • @stevecope
      @stevecope  4 года назад

      variable names are case sensitive so it wouldn't work.
      Rgds
      Steve

    • @biogasbrasil
      @biogasbrasil 4 года назад

      Steve Cope Yeah, that’s what i meant. You put it lower case and the variable actually was upper case. I wondered if that was the problem why you got “undefined”...but i guess I’ll just try it out later! Thanks again and congratulations for the great videos!

  • @jehan123456
    @jehan123456 5 лет назад +1

    I had a question why would we multiply the average with the count and then add it to the payload ?? trying to wrap my head around this

    • @stevecope
      @stevecope  5 лет назад +1

      Hi
      It is because the average is all readings/count.
      However we don't need to remember each of the previous readings as they are there in the current average.
      e.g 3+3+6 average=12/3=4
      or (3+3)/2 =3 (average)
      (3 (average)*2 +6)/3=4
      does that make sense?
      Rgds
      Steve

  • @quaternion-pi
    @quaternion-pi 5 лет назад

    Another fantastic tutorial. Can you point me where to learn about using node red with an external database like MongoDB or uploading my data in JSON format to my Google drive or Google docs spreadsheet (or dropbox)?
    Another confusing topic is how to send files from node red to other computers on my home network running windows or ubuntu. SSH via node-red??
    Thanks!

    • @stevecope
      @stevecope  5 лет назад

      Tks for the nice comment. I haven't seen anything on it but hope to be taking a look at that topic shortly.
      rgds
      steve

  • @fingerprint8479
    @fingerprint8479 3 года назад

    Hi, I am currently trying to design a NodeRed app that will respond to a http request with an http response containing a json string. My request arrives, I am able to build the json I want to return but formatting the response to feed on the html response node has been a challenge. Any suggestion on adapting your above design in an http response node? Thanks

    • @stevecope
      @stevecope  3 года назад

      Hi
      Contact me here
      and then you can send me the flow you have and I will take a look.
      stevesnoderedguide.com/ask-steve
      rgds
      steve

  • @horrorcoder
    @horrorcoder 5 лет назад

    Great tutorial Steve, thanks! Just check the download link on your site, it's giving a "permission denied" error

    • @stevecope
      @stevecope  5 лет назад +1

      Tks for pointing that out. It should be fixed now
      rgds
      steve

  • @ruofanli3361
    @ruofanli3361 5 лет назад

    thanks a lot !!!!!

  • @andreac3362
    @andreac3362 2 года назад

    So how do I get the JSON from an API ? If I am going to make up the data I can just set variables.

    • @stevecope
      @stevecope  2 года назад

      Not quite sure what you mean can you explain further.
      Rgds
      Steve

    • @andreac3362
      @andreac3362 2 года назад

      @@stevecope Creating the JSON to use it is a weird way to show how to use the data. We are going to get the data from someplace. ruclips.net/video/dZiqRg0o01E/видео.html

  • @chrissimpson4436
    @chrissimpson4436 Год назад

    Hello, how would you access the "Volts_5" from a nested array created this way below...
    JsonArray data = doc.createNestedArray("weatherstn");
    data.add(actionNum);
    data.add(valid);
    data.add(Volts_5);
    data.add(Volts_12);
    int b =serializeJson(doc, weatherS);
    boolean rc = client.publish("weatherstn", weatherS);
    Your video was very good but didnt cover nested arrays
    Many thanks (im trying to get data[2] to drive a gauge in node red dashboard

    • @stevecope
      @stevecope  Год назад

      Can you post the actual data that is created
      Rgds
      Steve

    • @chrissimpson4436
      @chrissimpson4436 Год назад

      @@stevecope Hi Steve, thanks for replying. I recover my Json data easily enough in other programs ... (like this for example, I am receiving json data from an arduino nano which collects the data and sends it serially to a arduino mega which displays the info, and then also sends it out via mqtt , below is the serial recovery)
      static StaticJsonDocument doc;
      if (Serial2.available() > 0){ // Is there stuff on serial 2 , if not jump over
      delay(10);
      String s = Serial2.readStringUntil('#'); // read it into a string
      //String s = "{\"a\":\"b\"}";
      while(Serial2.available() > 0){ // reads incoming serial data , returns -1 if no data
      Serial2.read();
      }
      Serial.print(s);
      deserializeJson(doc, s); // de - serialize string s

      temp3 = doc ["data"][0]; // beehive 18b20
      temp4 = doc ["data"][1]; // direct sun 18b20
      dhtHumidity1 = doc ["data"][2]; // beehive humidity
      But i am new to node red and i know it is pretty intuitive, and there is probably a dead easy way of recovery without writing a lot of code in a function node. the data back is like this..... this is a copy of the object
      {"weatherstn":[0,1,0,0,20.5625,-127,0,0,0,0,0,0,-127,-127,100,0,51,22.6,75,70,22.247,11.94184,1030,0,0,0,980,70,0,0,0,100,false,0,0,0,false,false,1,true,0,59000,-127,20.5625,0,0,0,6000,0,0,0,true,0,0,0,0,0,0]}
      (It is "weatherstn:array[58]")
      I have used node red to get a temp and graph going by single posting of a topic, but this sort of defeats the point of using json as it is great for bundling up lots of stuff
      kind regards Chris

    • @stevecope
      @stevecope  Год назад

      @@chrissimpson4436 sorry for late reply assumeing that the data is in the msg.payload then to get the first value from array 58 then try
      let result=msg.payload.weatherstn[58][0]
      rgds
      steve

  • @sharadpatle793
    @sharadpatle793 2 года назад

    Sir , how to resolve data length error in communication rs485

    • @stevecope
      @stevecope  2 года назад +1

      sorry but you need to provide more details.
      rgds
      steve

    • @sharadpatle793
      @sharadpatle793 2 года назад

      @@stevecope sir that problem is end