├── README.md ├── knitting_pattern_sample.json ├── knitting_pattern_schema.json └── validate.py /README.md: -------------------------------------------------------------------------------- 1 | # knitpat 2 | Knitting Pattern Format 3 | -------------------------------------------------------------------------------- /knitting_pattern_sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "file_url":"mypat.png", 3 | "name":"a small sweater", 4 | "dimensions":{ 5 | "image_length":80, 6 | "image_width":20, 7 | "physical_length":80.01, 8 | "physical_width":20.01, 9 | "units": "cm", 10 | "yarn_strength": 11 | { 12 | "units": "newtons", 13 | "value": 10 14 | } 15 | }, 16 | "colors":2 17 | } 18 | -------------------------------------------------------------------------------- /knitting_pattern_schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema":"http://json-schema.org/draft-04/schema#", 3 | "title":"KnittingPattern", 4 | "description":"A knitting pattern specification. Defines a file name and knitting specs.", 5 | "type":"object", 6 | "properties":{ 7 | "file_url":{ 8 | "description":"The name of the file that holds the pattern.", 9 | "type":"string" 10 | }, 11 | "name":{ 12 | "description":"Name of the pattern", 13 | "type":"string" 14 | }, 15 | "dimensions":{ 16 | "type":"object", 17 | "properties":{ 18 | "image_length":{ 19 | "type":"integer" 20 | }, 21 | "image_width":{ 22 | "type":"integer" 23 | }, 24 | "physical_length":{ 25 | "type":"number" 26 | }, 27 | "physical_width":{ 28 | "type":"number" 29 | }, 30 | "units":{ 31 | "type":"string" 32 | }, 33 | "yarn_strength":{ 34 | "type":"object", 35 | "properties":{ 36 | "units":{ 37 | "type":"string" 38 | }, 39 | "value":{ 40 | "type":"number" 41 | } 42 | } 43 | } 44 | } 45 | }, 46 | "colors":{ 47 | "type":"integer" 48 | } 49 | }, 50 | "required":[ 51 | "file_url", 52 | "name", 53 | "colors" 54 | ] 55 | } 56 | -------------------------------------------------------------------------------- /validate.py: -------------------------------------------------------------------------------- 1 | import validictory 2 | import json 3 | 4 | validate_file = file("knitting_pattern_sample.json", "rb") 5 | schema_file = file("knitting_pattern_schema.json", "rb") 6 | data = json.load(validate_file) 7 | schema = json.load(schema_file) 8 | validictory.validate(data, schema) 9 | --------------------------------------------------------------------------------