Next.js Discord

Discord Forum

JSON object changes when sent to server side?

Answered
Saltwater Crocodile posted this in #help-forum
Open in Discord
Avatar
Saltwater CrocodileOP
So I have an obj that looks like this when I log it from the client-side (in browser console):
{
    "type": "doc",
    "content": [
        {
            "type": "codeBlock",
            "attrs": {
                "language": "js"
            },
            "content": [
                {
                    "type": "text",
                    "text": "function(){\nconsole.log('test');\n}"
                }
            ]
        }
    ]
}

But when I log it from the server-side (in terminal) it looks like this:
content: {
    type: 'doc',
    content: [
      {
        type: 'codeBlock',
        attrs: [Function (anonymous)],
        content: [
          {
            type: 'text',
            text: "function(){\nconsole.log('test');\n}"
          }
        ]
      }
    ]
  }


attrs becomes a function? What could be the problem?
Answered by joulev
try structuredClone'ing the tiptap document before sending to the server. either structuredClone or JSON.parse(JSON.stringify(document))
View full answer

2 Replies

Avatar
try structuredClone'ing the tiptap document before sending to the server. either structuredClone or JSON.parse(JSON.stringify(document))
Answer
Avatar
Saltwater CrocodileOP
thanks, that solved the problem.