[prev in list] [next in list] [prev in thread] [next in thread] 

List:       esb-java-dev
Subject:    [Dev] $.. selector in javascript script mediator
From:       Bernard Paris <bernard.paris () uclouvain ! be>
Date:       2020-04-30 16:20:04
Message-ID: 7F6773C0-04CB-4ED0-877E-998CA8A0F28E () uclouvain ! be
[Download RAW message or body]

Hi devs,

I spent hours trying to select all "results" properties in a JSON payload within a \
javascript (script mediator), without success.

After
var payload = mc.getPayloadJSON();

I can easily select first levels "results" and get an array  with
var allResults = payload.results;

that works fine,  but selecting ALL "results" elements in the JSON (whatever the \
level there are) with var allResults = payload..results;

doesn't work and gives me an error
"The script engine returned an error executing the inlined js script function \
mediate." And strangely because my payload is json:
org.mozilla.javascript.EcmaError: TypeError: [object Object]  is not xml object.

How could I do this ?
Thanks for this,
Bernard


[Attachment #3 (text/html)]

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: \
after-white-space;" class=""> <div class="">Hi devs,</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">I spent hours trying to select all &quot;results&quot; properties in a \
JSON payload within a javascript (script mediator), without success.</div> <div \
class=""><br class=""> </div>
<div class="">After</div>
<div class=""><font face="Courier" class="">var payload = \
mc.getPayloadJSON();</font></div> <div class=""><br class="">
</div>
<div class="">I can easily select first levels &quot;results&quot; and get an array \
&nbsp;with</div> <div class=""><font face="Courier" class="">var allResults = \
payload.results;</font></div> <div class=""><br class="">
</div>
<div class="">that works fine, &nbsp;but selecting ALL &quot;results&quot; elements \
in the JSON (whatever the level there are) with</div> <div class=""><font \
face="Courier" class="">var allResults = payload..results;</font></div> <div \
class=""><br class=""> </div>
<div class="">doesn't work and gives me an error&nbsp;</div>
<div class="">&quot;The script engine returned an error executing the inlined js \
script function mediate.&quot;</div> <div class="">And strangely because my payload \
is json:</div> <div class="">org.mozilla.javascript.EcmaError: TypeError: [object \
Object] &nbsp;is not xml object.</div> <div class=""><br class="">
</div>
<div class="">How could I do this ?</div>
<div class="">Thanks for this,</div>
<div class="">Bernard</div>
<div class=""><br class="">
</div>
</div>
</body>
</html>



_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

--===============5151905805350552059==--

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic