parse part of http request


I receive an HTTP request from a plate reading camera which contains a whole series of information but only the plate number interests me.

The path is req.files[0].buffer

It's give are raw data and when i click on raw button i can see the data as string

Next, at the line "plateASCII":"XXX" I have the plate number.

I would like to be able to isolate only the plate number.

I installed the buffer-parser module, but I don't know how to isolate only the part of the message that interests me?

Can you help me?

Thanks in advance.


As the buffer is a binary representation of a string - which in your case is JSON - simply pass that through a JSON node to convert it to an Object where you will be able to get the path simply by dot notation.

Alternatively, in a function node...

msg.payload = JSON.parse(msg.req.files[0].buffer.toString())
return msg

Getting path to an item

There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.


Hi Steve,

Thanks for your help,

When I try your function, I've lintin error, do you know why?

I manage to have the data in string value whith buffer-parser module but I would like to isolate the plate number, I try with the split function but I must be doing something wrong

that error indicates the data is not valid JSON.

Your next best bet is REGEX in a function.

msg.payload = /"plateASCII":"([^"]*)"/.exec(msg.req.files[0].buffer.toString())[1]
return msg


Demo Flow:

[{"id":"9b24f668715455ab","type":"inject","z":"08c327c2653de72a","name":"","props":[{"p":"msg.req.files[0].buffer","v":"[123,34,116,104,105,115,34,58,34,116,104,97,116,34,44,34,112,108,97,116,101,65,83,67,73,73,34,58,34,65,66,67,49,50,51,90,34,44,98,97,100,95,106,115,111,110,58,32,49,50,51,122,125]","vt":"bin"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":990,"y":400,"wires":[["261a19c5f73840a1"]]},{"id":"261a19c5f73840a1","type":"function","z":"08c327c2653de72a","name":"regex","func":"msg.payload =  /\"plateASCII\":\"([^\"]*)\"/.exec(msg.req.files[0].buffer.toString())[1]\nreturn msg\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":990,"y":440,"wires":[["2cdd94e1793e65bf"]]},{"id":"2cdd94e1793e65bf","type":"debug","z":"08c327c2653de72a","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1000,"y":480,"wires":[]}]

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.