Assign query output to Class object

Primary tabs


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
  • 0
  • 0
  • 129
  • 7
  • 1



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:

Query Orgs() As %SQLQuery(CONTAINID = 1)
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:

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.