Pentaho

 View Only

 JSON.parse doesn't  work in javascript step

  • Pentaho
  • Pentaho
luiz kava's profile image
luiz kava posted 02-14-2019 14:16

I'm trying to get values from json, come from web-service, but when I try to use JSON.parse(variable), It throws a excepetion "SyntaxError: Unexpected token: t (script#4)". I'm sure that this script works, I work very well in other editor.

Below the mentioned json.

[

{

"id": "787365732584980480",

"numeroProposta": "151041",

"cliente": {

"id": "779795407335784449",

"idExterno": "FUNCAO_06170733926",

"emails": [

{

"email": "tatata@tata.tata.pr.gov.br"

}

]

},

"condicoes": [

{

"id": "787365732589174784",

"numeroParcelas": "0"

}

],

"acaoId": "758657009895284736",

"acaoNome": "AcaoDescontoNatalAntecipado"

}

]

And this is my javascript step

jsonerror


#Pentaho
Paulo Pires's profile image
Paulo Pires

Hi Luiz,

You need to set the Compatibility mode on, just click on the checkbox in the bottom of the script window.

Best regards

luiz kava's profile image
luiz kava

Thanks Paulo, but I've already tried it, also doesn't work

Paulo Pires's profile image
Paulo Pires

I did something similar a few days ago.

My json to parse was of type string before the javascript step, so make sure your result or resultado is a string.

Best regards

luiz kava's profile image
luiz kava

thanks man, I managed to do.

tell me now, I'm trying to generate a new row each object from my array json, do you know how to do?

my loop overrides the last value, so at the end I've just one row, even my json having many objects.

Paulo Pires's profile image
Paulo Pires

For that probably the best would be to use the JSON Input step for the result column, and then convert the columns to rows.

Best regards

luiz kava's profile image
luiz kava

I managed to make thanks to you....

Your help was so helpfull, thanks a lot Paulo