Extract data, strings, parsers,

Hello, How can I extract specific data if I have this result? for example using a pastebin :

{
  "content": "[\r\n  {\r\n      \"id\": 157538,\r\n      \"date\": \"2017-07-21T10:30:34\",\r\n      \"date_gmt\": \"2017-07-21T17:30:34\",\r\n      \"guid\": {\r\n          \"rendered\": \.......      \"title\": {\r\n          \"rendered\": \"Why the IoT Threatens Your WordPress Site (and How to Fix It)\....    \"categories\": [\r\n          6132\r\n      ],\r\n      \"tags\": [\r\n          1798,\r\n          6298\r\n      ],\r\n\r\n      }\r\n  ]"
}

Hi @dinolabs and welcome to our community. I think this is a bug in how data is being returned in the piece. I’ll mark this as a bug and wait for @abuaboud to confirm it.

Sorry, I thought you had only text in the paste and the JSON wasn’t parsed correctly at our end.

This is not a bug. You can use the content you are getting and find the value you’re looking for with one of the helpers or a code step.

For example, you can write code to read this content and parse it as JSON and return it.

Does this make sense to you?

Hello, the result is the same:
the code:

{
  "studentid" : 101,
  "firstname" : "John",
  "lastname" : "Doe",
  "isStudent" : true,
  "classes" : [
    "Business Research",
    "Economics",
    "Finance"
  ],....```

activepieces: 

{
  "content": "{\r\n  \"studentid\" : 101,\r\n  \"firstname\" : \"John\",\r\n  \"lastname\" : \"Doe\",\r\n  \"isStudent\" : true,\r\n  \"classes\" : [\r\n    \"Business Research\",\r\n    \"Economics\",\r\n    \"Finance\"\r\n  ],\r\n  \"getFullName\" : function(){\r\n    alert(`${this.firstname} ${this.lastname}`);\r\n  } \r\n}"
}

After understanding how you can pass data between the steps in your flow, you can add a Code step that does return JSON.parse(inputs.content); in order to convert this content into an actual JSON object.

How can I do that? :pleading_face:

I don’t see a full example here :pleading_face:

Add a Code step after the Pastebin step in your flow. In the inputs, type content as the key and in the value, choose the data coming from the Pastebin step.

Then write this code:

export const code = async (inputs) => {
    return JSON.parse(inputs.content);
};

Let me know how it goes.

After trying, there is an error:

SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse ()
at Object.code (/root/codes/WyILBPNbKsi1fexq3CpPT/index.js:5:17)
at Object. (webpack://activepieces/engine/src/lib/executors/code-executer.ts:9:30)
at Generator.next ()

Show me your Code step settings please

The paste bin content:

sure, here my configuration:

Did you name it “content” or “parrafo”? You will need to use the same word everywhere, including in the code I sent to you.

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