Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Validating JSON with Script Steps can be tedious. For example, If I want to val
![](docs/oldway.png)

### Imperitive Vs Declaritive
This tedious becuase we have to tell FileMaker how to validate the object imperitively. If we could simply "Declare" our rules it would be easier.
This tedious because we have to tell FileMaker how to validate the object imperatively. If we could simply "Declare" our rules it would be easier.

Here is that same logic usign Custom Functions to Declaratively validate our JSON

Expand All @@ -25,7 +25,31 @@ If all rules failed passed we'd get
If any of these rules fail we'll get an Error as the result of this function. If they all failed it would look like this. Notice the individual errors are added to an "errors" property.

```json
{ "errorCode" : -2, "errors " : [ { "descriptor" : "Required value is missing", "errorCode" : -2, "path" : "firstName", "type" : "JSON.Validate" }, { "descriptor" : "Required value is missing", "errorCode" : -2, "path" : "lastName", "type" : "JSON.Validate" }, { "descriptor" : "Should be one of male,female", "errorCode" : -2, "path" : "gender", "type" : "JSON.Validate" } ], "type" : "JSON.Validate"}
{
"errorCode" : -2,
"errors " :
[
{
"descriptor" : "Required value is missing",
"errorCode" : -2,
"path" : "firstName",
"type" : "JSON.Validate"
},
{
"descriptor" : "Required value is missing",
"errorCode" : -2,
"path" : "lastName",
"type" : "JSON.Validate"
},
{
"descriptor" : "Should be one of male,female",
"errorCode" : -2,
"path" : "gender",
"type" : "JSON.Validate"
}
],
"type" : "JSON.Validate"
}
```

This "error" JSON follows the format we have described [in the Error Custom Function Repo](https://github.com/karbonfm/fm-error-functions). There is a function in that set, called `Error.IsError()`, that can detect if the above JSON is an "error"
Expand All @@ -34,4 +58,4 @@ This "error" JSON follows the format we have described [in the Error Custom Func

Check out the Tests in the JSON.Validate.fmp12 file. They should show you how to use it.

Also each function is documented [here](docs/index.md) and in the CF itself.
Also each function is documented [here](docs/index.md) and in the CF itself.