Webmethods: Validating Document structure?

Hello, I’d like to know how to validate documents. For instance, I have this document type (based on JSON) where an example of an accepted input is like:

{ "people": [
  {"firstName":"Joe","lastName":"Jacky","age":21},
  {"firstName":"Dana","lastName":"Salis","age":20}
  ]
}

Now, during the flow service, I want to make sure that the inserted input follows exactly like such format. So if even so much the name of the elements are different, then it catches an error. Therefore, if the input is like this:

{ "peoples": [
  {"firstName":"Joe","lastName":"Jacky","age":21},
  {"firstName":"Dana","lastName":"Salis","age":20}
  ]
}

Then it throws an error because it doesn’t have an element called ‘peoples’.

How do I put such validation? Because the last I tried that, the designer just accepted as it is and didn’t throw an error.

Thanks.

@kristian.wijaya1234

  1. Create JSON documentType against your json Schema. Designer — Right click – Create JSON Document Type ( Not regular document Type )

    image

    You can create json Schema in any online or json tool using your json input string which you want to validate.

  2. Execute pub.json.schema:validate - Pass json string and json document type name

    if your input json string is against your json documentType then isValid will be false and error.message will hint you the errored one.

I hope this helps you.

1 Like

@DINESH_J Can you tell me about how to put in the conformsTo part? I get the idea that you’re directing to the JSON Document Type you just made, but I’m not sure how to locate that package-wise.

I get the idea that you use this:

testRESTPackage (Package) → people (JSON Document Type)

Is that correct or wrong?

Then, what if the location is this, how do I change that to conformsTo?

testRESTPackage (Package) → documents (folder) → people (JSON Document Type)

Thanks.

@kristain , In webMethods if we are referring against any elements at runtime it should be always fully Qualified Name . The fully qualified service name is comprised of two parts: a folder identifier and the service name

testRESTPackage(Folder name )–> People (element name).

so just right click and copy the name from designer of your JSON documentType and provided as confirmTo of validate service

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.