web stats
json schema parsing for jsonrpc messages - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 05-20-2017, 06:18 AM
sBham sBham is offline
Mirth Newb
 
Join Date: Feb 2017
Posts: 6
sBham is on a distinguished road
Default 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"}


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

Thx
-sBham
Reply With Quote
  #2  
Old 05-22-2017, 02:07 AM
siddharth siddharth is offline
Mirth Guru
 
Join Date: Feb 2013
Posts: 832
siddharth is on a distinguished road
Default

Do you want to validate a JSON that you receive in the channel against a pre-defined JSON structure?
Reply With Quote
  #3  
Old 05-22-2017, 04:12 AM
sBham sBham is offline
Mirth Newb
 
Join Date: Feb 2017
Posts: 6
sBham is on a distinguished road
Red face

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:
https://github.com/java-json-tools/j...hema-validator

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??

Thanks
sBham
Reply With Quote
  #4  
Old 05-22-2017, 04:42 AM
siddharth siddharth is offline
Mirth Guru
 
Join Date: Feb 2013
Posts: 832
siddharth is on a distinguished road
Default

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!
Reply With Quote
  #5  
Old 05-22-2017, 06:23 AM
sBham sBham is offline
Mirth Newb
 
Join Date: Feb 2017
Posts: 6
sBham is on a distinguished road
Default

Thank you for the feedback!
Reply With Quote
  #6  
Old 05-22-2017, 06:25 AM
sBham sBham is offline
Mirth Newb
 
Join Date: Feb 2017
Posts: 6
sBham is on a distinguished road
Default

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!
Reply With Quote
Reply

Tags
json, postgres, rpc, schema

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 06:28 PM.


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