jsonata-js/jsonata

How to return the value from jsonata instead of promise/async

sureshssb07 opened this issue · 3 comments

Hi,

We are trying to fetch the value from jsonata and return the result to another method. below is the sample code which we are trying but it always returning promise with pending. so is there any possible to call jsonata with sync method or return value from jsonata

Ex: Code :
const jsonata = require('jsonata');
async function CallJsonAta()
{
const body = {
"data" : {
"title" : "title1",
"description": "description1",
"blog": "This is a blog.",
"date": "11/4/2013"
},
"map" : "sample"
};
let out = JSON.parse(JSON.stringify(body));
let result = await jsonata('data.title').evaluate(out);
return result;
}
console.log("Result : ", CallJsonAta());

Actual Output:
Result : Promise { < pending > }

Expected Output:
Result : title1

Change your last line to console.log("Result : ", await CallJsonAta());

Thanks for your quick Reply

But

i tried with yours option but getting below exception

console.log("Result : ", await CallJsonAta());
^^^^^

SyntaxError: missing ) after argument list
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1166:20)
at Module._compile (node:internal/modules/cjs/loader:1210:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1300:10)
at Module.load (node:internal/modules/cjs/loader:1103:32)
at Module._load (node:internal/modules/cjs/loader:942:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
at node:internal/main/run_main_module:23:47

Node.js v19.5.0

Can you post the whole code?