Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sureshssb07 opened this issue Oct 5, 2023 · 3 comments
Open

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

sureshssb07 opened this issue Oct 5, 2023 · 3 comments

Comments

@sureshssb07
Copy link

sureshssb07 commented Oct 5, 2023

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

@andrew-coleman
Copy link
Member

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

@sureshssb07
Copy link
Author

sureshssb07 commented Oct 5, 2023

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

@dakhnod
Copy link

dakhnod commented May 25, 2024

Can you post the whole code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants