Mirth Community

Mirth Community (http://www.mirthcorp.com/community/forums/index.php)
-   Support (http://www.mirthcorp.com/community/forums/forumdisplay.php?f=6)
-   -   json schema parsing for jsonrpc messages (http://www.mirthcorp.com/community/forums/showthread.php?t=217182)

sBham 05-20-2017 06:18 AM

json schema parsing for jsonrpc messages
Hey there,

I was wondering what the community would recomment for efficiently validating json messages that I was provided json schema for. (it seems like json schema is almost like the usual equivalent in XML world).

In this case the implementation is both http and channel listners and the goal is to validate the json payload at the source filters using either: filter steps, a custom java jar that would expose a json schema parsing method to validate a message against its corresponding scheam. Or some type of javascript library at the transformation?

In this case we are talking about close to 100 different message contracts/format I was given (and same for response). So implemeting filters for each field might be a daunting task especially if I was given the json schema for each request and response. there are libraries out there that would validate a json document against a json schema (just like we have in XML world)

In either java or node.js I would have used one of the json schema libraries available (http://json-schema.org/implementations#validator-java). However before I start validation work, I would like to query the community and support for what would be the recommended most efficient ways or alternative solutions.

Format/schema of request json payload:

{"method": "methodName",
"id": "arbitrary-something",
"params": [arg1, arg2, ...]}

Format/schema of response json payload:

{"result": the_result,
"error": null,
"id": "arbitrary-something"}

Mirth connect 3.5 (and final solution to be ultimately deployed on an appliance)


siddharth 05-22-2017 02:07 AM

Do you want to validate a JSON that you receive in the channel against a pre-defined JSON structure?

sBham 05-22-2017 04:12 AM

yes exactly!

The json/message structure in this case is provided as a json schema format document. in this case I was given ~60 schemas. So I am comparing using filters and checking for segment existance/type... VS using a cutom jar that would validate a message against a schema.

I found a few java libraries that validates a json document against a json schema. example at:

But wanted to know if I am going about it the correct way (is it more efficient to use filters vs jar), or if there are other better recommended ways??


siddharth 05-22-2017 04:42 AM

That is actually the way!. You are on right track.

If you wanted to validate an HL7 message there is an internal Mirth parser (strict parser) that can do that, because the format/placeholders are pre-defined.

In terms of XML, and JSON the format is pretty much open, you can have anything as long as it is syntactically correct - closing tags, curly braces etc.

If you want to validate your incoming JSON to a defined JSON schema, you have to take help of custom-libs, and while you are doing so, do that in a JS Reader where you can write complete validation code, instead of partially relying on Mirth Filters.

Good luck!

sBham 05-22-2017 06:23 AM

Thank you for the feedback!

sBham 05-22-2017 06:25 AM

Maybe for a future mirth release we could get builtin helper util classes/methods to validate json or xml against a validation schema !

Thank you!

All times are GMT -8. The time now is 02:47 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation