README.md in strong_json-0.1.2 vs README.md in strong_json-0.2.0
- old
+ new
@@ -28,11 +28,12 @@
let :item, object(id: prohibited, name: string, count: numeric)
let :custoemr, object(name: string, address: string, phone: string, email: optional(string))
let :order, object(customer: customer, items: array(item))
end
-json = s.order.coerce(JSON.parse(input))
+json = s.order.coerce(JSON.parse(input), symbolize_names: true)
+s.order =~ JSON.parse(input, symbolize_names: true)
```
If the input JSON data conforms to `order`'s structure, the `json` will be that value.
If the input JSON contains attributes which is not white-listed in the definition, it will raise an exception.
@@ -55,26 +56,38 @@
### optional(type)
* The value can be `nil` (or not contained in an object)
* If an value exists, it must be of given `type`
+### enum(type1, type2, ...)
+
+* The value can be one of the given types
+* First successfully coerced value will return
+
### Base types
* `number` The value must be an instance of `Numeric`
* `string` The value must be an instance of `String`
* `boolean` The value must be `true` or `false`
* `numeric` The value must be an instance of `Numeric` or a string which represents a number
* `any` Any value except `nil` is accepted
* `ignored` Any value will be ignored
+* `symbol` The value must be an instance of `String` or `Symbol`; returns the result ot `#to_sym`
+### Literals
+
+* `literal(lit)` The value must `=== lit`
+
### Shortcuts
There are some alias for `optional(base)`, where base is base types, as the following:
* `number?`
* `string?`
* `boolean?`
* `numeric?`
+* `symbol?`
+* `literal?(lit)`
Shorthands for `optional(array(ty))` and `optional(object(fields))` are also defined as the following:
* `array?(ty)`
* `object?(fields)`