Converting JSONata to valid JSON
See original GitHub issueIs there a way to convert JSONata string to valid JSON ? Assumption : JSONata string does not involve any function declarations.
Example :
var script = `{
"source": source,
"data":
{
"name" : data.payload.Name.(FirstName & ' ' & LastName),
"alias": data.payload.Name.(Salutation & ' ' & FirstName),
"active": data.payload.Status = 'New' ? true : false,
"signature": "Have good day ," & data.payload.Name.FirstName & "!"
}
}`;
Is there a way to convert above to JSON like this :
{
"source": "source",
"data": {
"name": "data.payload.Name.(FirstName %26 %27 %27 %26 LastName)",
"alias": "data.payload.Name.(Salutation %26 %27 %27 %26 FirstName)",
"active": "data.payload.Status = %27New%27 ? true : false",
"signature": "%22Have good day ,%22 %26 data.payload.Name.FirstName %26 %22!%22"
}
}
All special character has been encoded using escape() function in javascript.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
String functions · JSONata
Strings are unchanged; Functions are converted to an empty string; Numeric infinity and NaN ... If prettify is true, then "prettified" JSON is...
Read more >Applying JSONata functions to transform your data - IBM
When editing a target field in a flow, you can add a transform function to ... If a JSONata expression is not valid,...
Read more >JSONata Cheatsheet - Stedi Docs
All mappings expressions are based on JSONata language - this page showcases its most important features useful when creating a mapping.
Read more >Convert String to JSON Objects in JavaScript with eval()
String data can be converted to JSON using the stringify() function or eval(), which accepts the JavaScript expression you will learn about ...
Read more >10 Examples to Help You Learn JSONata - Blues Wireless
This guide's examples all take the same input JSON (shown below), and use JSONata to query or transform that input in interesting ways....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This feels like a Javascript discussion. I will close it here and let the discussion continue on stack overflow.
@jhorbulyk …
Gives error :
TypeError: Cannot read property 'name' of undefined