1. dcutting
  2. VeriJSON

Commits

dcutting  committed 89b99ce

Updated README to describe pattern format.

  • Participants
  • Parent commits 7685cfc
  • Branches default

Comments (0)

Files changed (2)

File README.md

View file
 # VeriJSON
 
 An Objective-C library for verifying JSON against a pattern-based schema.
+
+# Patterns
+
+A pattern describes the expected content of a JSON document. Patterns are themselves valid JSON, and mirror the structure of a matching JSON document by including property names, arrays and objects. Instead of values, a pattern specifies the required type of values.
+
+Allowed types are "number", "string" and "bool". Arrays and objects are represented structurally.
+
+A sample pattern:
+
+    {
+        "id": "number",
+        "name": "string",
+        "price": "number",
+        "discounted": "bool",
+        "manufacturer": {
+            "name": "string"
+        },
+        "properties": [
+            {
+                "name": "string",
+                "value": "string",
+                "tags": [ "string" ]
+            }
+        ]
+    }
+
+A JSON document that successfully matches the pattern:
+
+    {
+        "id": 1,
+        "price": 12.50,
+        "name": "A green door",
+        "manufacturer": {
+            "name": "ACME"
+        },
+        "discounted": true,
+        "properties": [
+            {
+                "name": "blah",
+                "value": "whatever",
+                "tags": [ "great" ]
+            },
+            {
+                "name": "foo",
+                "value": "bar",
+                "tags": [ ]
+            }
+        ]
+    }
+
+By default, all properties in the pattern are mandatory. JSON documents omitting the properties are not considered to match. However, properties appearing in the JSON document that are not part of the pattern are ignored and considered to match.
+
+# Optional properties
+
+If a property within an object is optional, suffix its name in the pattern with a question mark '?'.
+
+For example:
+
+	{
+        "id": "number",
+        "name": "string",
+        "discounted?": "bool"
+    }
+
+All of the following JSON documents successfully match this pattern:
+
+	{
+        "id": 4,
+        "name": "A green door",
+        "discounted": true
+    }
+
+	{
+        "id": 4,
+        "name": "A green door"
+    }
+
+	{
+        "id": 4,
+        "name": "A green door",
+        "discounted": null
+    }
+
+Note that an optional property may also have a "null" value. This is not true of non-optional properties.
+
+# Regular expressions
+
+The string type may also include an optional regular expression to which a value must conform.
+
+	{
+	    "date": "string:\\d{8}"
+	}
+
+Matches:
+
+	{
+	    "date": "20130101"
+	}
+
+Does not match:
+	
+	{
+	    "date": "130101"
+	}

File VeriJSON.xcodeproj/project.pbxproj

View file
 		C8A69A6C169203DB0038211F /* ObjectWithBoolInvalid.json in Resources */ = {isa = PBXBuildFile; fileRef = C8A69A69169203DB0038211F /* ObjectWithBoolInvalid.json */; };
 		C8A69A6D169203DB0038211F /* ObjectWithBoolPattern.json in Resources */ = {isa = PBXBuildFile; fileRef = C8A69A6A169203DB0038211F /* ObjectWithBoolPattern.json */; };
 		C8A69A70169206370038211F /* ObjectWithBoolAsNumber.json in Resources */ = {isa = PBXBuildFile; fileRef = C8A69A6F169206370038211F /* ObjectWithBoolAsNumber.json */; };
+		C8CEF67E1694DD4D0098937F /* LICENSE.txt in Resources */ = {isa = PBXBuildFile; fileRef = C8CEF67C1694DD4D0098937F /* LICENSE.txt */; };
+		C8CEF67F1694DD4D0098937F /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = C8CEF67D1694DD4D0098937F /* README.md */; };
 		C8E11E151691D69600C36062 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C8E11E141691D69600C36062 /* UIKit.framework */; };
 		C8E11E171691D69600C36062 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C8E11E161691D69600C36062 /* Foundation.framework */; };
 		C8E11E191691D69600C36062 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C8E11E181691D69600C36062 /* CoreGraphics.framework */; };
 		C8A69A69169203DB0038211F /* ObjectWithBoolInvalid.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = ObjectWithBoolInvalid.json; path = Data/ObjectWithBoolInvalid.json; sourceTree = "<group>"; };
 		C8A69A6A169203DB0038211F /* ObjectWithBoolPattern.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = ObjectWithBoolPattern.json; path = Data/ObjectWithBoolPattern.json; sourceTree = "<group>"; };
 		C8A69A6F169206370038211F /* ObjectWithBoolAsNumber.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = ObjectWithBoolAsNumber.json; path = Data/ObjectWithBoolAsNumber.json; sourceTree = "<group>"; };
+		C8CEF67C1694DD4D0098937F /* LICENSE.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE.txt; sourceTree = "<group>"; };
+		C8CEF67D1694DD4D0098937F /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.md; sourceTree = "<group>"; };
 		C8E11E101691D69600C36062 /* VeriJSON.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VeriJSON.app; sourceTree = BUILT_PRODUCTS_DIR; };
 		C8E11E141691D69600C36062 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
 		C8E11E161691D69600C36062 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
 		C8E11E051691D69600C36062 = {
 			isa = PBXGroup;
 			children = (
+				C8CEF67D1694DD4D0098937F /* README.md */,
+				C8CEF67C1694DD4D0098937F /* LICENSE.txt */,
 				C8E11E1A1691D69600C36062 /* VeriJSON */,
 				C8E11E3E1691D69600C36062 /* VeriJSONTests */,
 				C8E11E131691D69600C36062 /* Frameworks */,
 				C8E11E291691D69600C36062 /* Default@2x.png in Resources */,
 				C8E11E2B1691D69600C36062 /* Default-568h@2x.png in Resources */,
 				C8E11E2E1691D69600C36062 /* MainStoryboard.storyboard in Resources */,
+				C8CEF67E1694DD4D0098937F /* LICENSE.txt in Resources */,
+				C8CEF67F1694DD4D0098937F /* README.md in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};