How to convert extracted data into json?

Describe the problem/error/question

I’m trying to get a list of artistName, how can I do this? I’ve extracted the json from #serialized-server-data but I don’t know how to convert it into json so I get artistName from it

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 2.1.5
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): npm
  • Operating system: Ubuntu 24.04 LTS

the html content from script tags should already be valid json stringified — thats what #serialized-server-data usually contains. try using a code node with JSON.parse(data) to convert it, then youll be able to access artistname directly. if the parser fails check for extra whitespace or syntax issues in the extracted string first.

Hi @Ruriko, welcome back,

You’re almost there! Just change the Return Value to HTML instead of Text:

Then everything should work as expected:

2 Likes

Hi! I checked your workflow and the issue is actually quite straightforward once you look at how the data flows.

:magnifying_glass_tilted_left: What’s happening

  • In your HTML node, you extract:

    #serialized-server-data
    
  • This returns a string, not a JSON object.

So even though it looks like JSON, n8n still treats it as plain text.


:red_exclamation_mark: Why it doesn’t work directly

The value in album is:

  • a JSON string

  • extracted from a <script> tag

  • not parsed yet

So when you pass it into Edit Fields, it’s still just a string → you can’t access properties like artistName.


:white_check_mark: Root cause

:backhand_index_pointing_right: The problem is: data is still a string (not parsed yet)


:brain: What’s missing

There is currently no node that converts the string into JSON.


:hammer_and_wrench: Minimal fix (no redesign needed)

Add a Code node after the HTML node:

let raw = $json.album;

// clean possible script tags (just in case)
raw = raw
  .replace(/<script[^>]*>/, '')
  .replace('</script>', '')
  .trim();

// parse to JSON
const parsed = JSON.parse(raw);

// now you can access data
return {
  json: parsed
};

:bullseye: After that

You can access fields like:

$json.data[0].attributes.artistName

(depending on the exact structure)


:light_bulb: Summary

  • HTML node → returns string

  • No parsing step → main issue

  • Add Code node with JSON.parse() → solved


If you share a sample of the extracted album content, I can help point to the exact path for artistName.

nice breakdown @erwin_burhanudin — the script tag cleanup is a good catch. once it’s parsed, just explore the structure in the output panel first to find the exact path to artistName.

1 Like

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