TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Socket'
| property 'parser' -> object with constructor 'HTTPParser'
--- property 'socket' closes the circle
What are you doing when this happens? (show us your flow)
Where do you see this error? (in console? in debug panel?)
What version of NodeJS and Node-RED are you running?
What platform are you running on?
iam trying to write the api response into a parquet file.
- i recived the api result in the form of array msg.payload.organic_result.
- i redeclared a new array and parsed the result into this new array and again reassigned it to msg.payload beacuse (write node) it requires input in the form of an array buffer.
And the other questions?
TBH, I think this is related to the http-in --> http-request --> http-response
- since they both use msg.req
and msg.res
The msg
from http-in
must be ultimately passed back to the http-response
without being destroyed/changed/lost - however when you pass the msg
to a http-request
I think that is where the error occurs (I am guessing since you have not answered "Where do you see this error? (in console? in debug panel?)"
FYI: If you see an error in the debug panel, you can "mouse over" it and the failing node will blink!
what exactly is the file structure
node? Is that a regular Write File
node? Or is it something else you have installed?
As @Steve-Mcl alluded to, the fact the message being received by that node comes from an HTTP In
node originally, it will have msg.req
and msg.res
set on it. These are the request/response objects for the original HTTP request that triggered the flow. These properties cannot be JSON encoded - for exactly the error you are hitting.
So the better approach would be to change your flow to not try encoding the whole message - just encode the bit you want, such as msg.payload
. You'll need to keep msg.res
on the message as that is needed by the HTTP Response
node you must have somewhere in your flow to respond to the original http request.
file structure node contains coulmn head and the type of data it can hold and it should be similar to that of the data in the array.
You have not answered the questions I asked. It makes it hard for us to help if we have to keep asking the same questions to get them answered.
Is the File Structure node:
- a node you have created yourself?
- a core Node-RED node that you have just set the name of to 'file structure'?
- a node you have installed yourself? If so, what module did you install to get it?
I have given an explanation of why you are hitting this error. I have made a couple suggestions on how to fix your flow. But I cannot be any more specific because of the missing information.
That looks like that node is doing something with the full msg. Try sending a new msg with the required payload...
PS
It is FAR better to paste code so that we dont have to screenshot and overwrite with boxes and arrows.
Plus, screenshots are not searchable! They are fine for showing us what you have, but please paste code as text in a </>
formatted code block. Thanks.
Hi @knolleary
i'am really sorry for the inconvenience actually i'am very new to node-red ,from next time i'll keep that
in mind and thanks for answering my queries.
i have installed the node from here:
hey i tried your solution but the file structure node is unable to write the array into the file.
let length = msg.payload.organic_results;
const arr=[];
for(let i=0;i<length;i++){
const obj2={
"position" : msg.payload.organic_results[i].position,
"title": msg.payload.organic_results[i].title,
"link": msg.payload.organic_results[i].link
};
arr[i]=obj2;
}
const newMsg={payload : arr};
return newMsg;
when it is passed to ------------->file structure node (it is taking payload as empty array)
{"payload":[ ],"_msgid":"31870f549f46772d"}
ADMIN EDIT: Wrapped code with 3 ```
backticks
Add debug nodes BEFORE and AFTER to see if the right stuff goes into your function and the msg is correct afterwards.
To determine what is happening inside your function, use node.warn(...)
...
let length = msg.payload.organic_results;
node.warn( [ "length", length] )
const arr=[];
for(let i=0;i<length;i++){
const obj2={
"position" : msg.payload.organic_results[i].position,
"title": msg.payload.organic_results[i].title,
"link": msg.payload.organic_results[i].link
};
node.warn( [ "setting new object into arr[index]", i, obj2] )
arr[i]=obj2;
}
const newMsg={payload : arr};
node.warn( [ "Created new msg object - inspect it", newMsg] )
return newMsg;
(untested - may be typos)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.