cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement jsonschema validation using Python script

Ajay_Chawda
Contributor

Hi
i’m trying to validate simple json data against particular json schema using python script.
i’m trying to use ‘cerberus’ library of python but script snap is failing with error.
image

How we can import external library and use it in script snap?any other native library that can be use so that we can avoid loading of external library?

JSON Formatter snap can be used to validate json by specifying Schema file ?

validate_2019_01_02.slp (10.4 KB)

test.schema.txt (366 Bytes)

5 REPLIES 5

tlikarish
Employee
Employee

Try checking out this post and see if that can help get you started. How to use 3rd party python libraries in python Script - #6 by Bhavin. I believe the script snap uses Jython to execute and so you may only be able to import Java libraries for use in the script.

Ajay_Chawda
Contributor

Hi ,
as suggested in post ,i have added “json-schema-validator-2.1.7.jar” .
image

error maessage:-
image

validate_2019_01_03.slp (10.5 KB)

tlikarish
Employee
Employee

I don’t think the approach I suggested will work unless you can add the dependency to the plex node you are running the script on. Are you running this on a groundplex or a cloudplex? I assume if you’re a trial user, then you probably have a cloudplex in which case this isn’t going to work.

Let me ask around and see if anyone else can think of a solution that works for you.

tlikarish
Employee
Employee

So I talked with a couple people and here are some options. You can use a snap called the DataValidator that allows some similar options to what JsonSchema provides. Here is an example that uses constraints similar to what you were looking to do.

data-validator-example_2019_01_09.slp (5.8 KB)

The other option is to use some of the XML snaps as those have validation built into them. I guess the data validation is more common with the XML use cases from what we’ve seen. So you could do something like this, which would do the validation in the XML snaps.

image