Assign query output to Class object
I want to assign below query result into my Person class which have Name,DOB properties, and then convert into JSON.
SELECT Name,DOB FROM Sample.Person
I want to assign below query result into my Person class which have Name,DOB properties, and then convert into JSON.
SELECT Name,DOB FROM Sample.Person
A few more details about your exact use case would help me give a better answer here. As for the exact questions you asked, here's an example of the syntax you can use to write a query as part of a class:
{
SELECT ID As OrgID,Name,DisplayName FROM Org ORDER BY Name
}
As for getting the query result as JSON, I asked a similar question a little while ago, and this discussion was very useful:
https://community.intersystems.com/post/how-do-i-return-json-database-sq...
Now, if your real question is something along the lines of "I want to write a REST endpoint that gives me back the result of a class query in Person as JSON", then unfortunately that's a non-trivial problem. The fastest way would be to write some endpoint, like /basicpersoninfo, and have the REST handler route requests for that endpoint to a method that uses JSON_ARRAYAGG and JSON_OBJECT and dynamic SQL (discussed in that other thread) to write out the results of that query in JSON.
Starting from 2019.2 there's a %JSON.Adapter, for automatic bidirectional JSON<>Object transformation.
That's true. If your query really is that simple, definitely look at Mappings in this:
https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...
Wrapping a class query in JSON is only necessary for more complex class queries.
It doesn't seem to work on 2019.0
What doesn't work in 2019.0?
Also do you mean 2019.1.0?
Hi Ed!
Does RestForms leverage %JSON.Adapter functionality to expose classes data to REST via JSON?
Check RESTForms project, it does similar things (articles: part1, part2).
Not yet.