Announcement

Collapse
No announcement yet.

json schema parsing for jsonrpc messages

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #2
    Do you want to validate a JSON that you receive in the channel against a pre-defined JSON structure?
    HL7v2.7 Certified Control Specialist!

    Comment


    • #3
      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

      Comment


      • #4
        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!
        HL7v2.7 Certified Control Specialist!

        Comment


        • #5
          Thank you for the feedback!

          Comment


          • #6
            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!

            Comment

            Working...
            X