On a related note, if anyone who's involved in the development of the core product sees this, is the * syntax, where we actually get the name of the oref that was invalid (similar to the *variable syntax we get when a reference is undefined) in the plans for the future?

Thanks I'll look into this.

We've been using this tool as the backbone of our REST APIs that serve persistent data to Angular UI's.  It's extremely useful and powerful, glad to see it progressing even more.

As a follow up to this, if you're using the ##class(class name).myMethod(args) syntax and it's not working, it may be that you're trying to call an instance method, a method called on an object instance of your class, rather than a class method, a method called on the class itself.

In that case, you'd want to try something like:

set myObj = ##class(class name).%New()

do myObj.myMethod(args)

Hope this helps!

Can confirm that the %JSON.Adaptor tool is extremely useful!  This was such a great addition to the product.

In Application Services, we've used it to build a framework which allows us to not only expose our persistent classes via REST but also authorize different levels of access for different representations of each class (for example, all the properties, vs just the Name and the Id).  The "Mappings and Parameters" feature is especially useful:

Also, @Stefan are you writing backwards while you talk?  That's impressive.

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.

Oh, okay!  I think the fastest way to get to what you want would be front end form validation.

Whatever you're using to build the UI that leads to this JSON post, have that code mark certain fields as required, and then alert if those aren't filled.  In general, I think in the division of labor that task typically falls to the front end.

In theory, you can write a server method that scans the input before JSON import and then throws a custom exception with all the missing fields, but that's likely more work than doing it on the front end (because the front end will still have to catch that, then assemble the alert message from it anyway).

Also, if you're going to be changing which fields are required a lot, you can (in theory) write a server method which exposes which fields are required, instead of hard-coding that in the front end, but, again, that's likely not worth the effort.

Any of that helpful, or am I misunderstanding the problem?

I believe the %JSON import method returns after hitting an error like that, so it's probably more work than you think to have the error give you all fields that are required and empty.

But could you be a little more specific about your use case and exactly what problem you're trying to solve?  There might be a better way.