1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "schema": {
12 "$schema": "https://json-schema.org/draft/2020-12/schema",
13 "type": "object",
14 "required": [
15 "id",
16 "email",
17 "age"
18 ],
19 "properties": {
20 "id": {
21 "type": "integer",
22 "minimum": 1
23 },
24 "email": {
25 "type": "string",
26 "format": "email"
27 },
28 "age": {
29 "type": "integer",
30 "minimum": 0,
31 "maximum": 120
32 },
33 "role": {
34 "enum": [
35 "admin",
36 "editor",
37 "viewer"
38 ]
39 }
40 },
41 "additionalProperties": false
42 },
43 "items": [
44 {
45 "id": 1,
46 "email": "ana@example.com",
47 "age": 34,
48 "role": "admin"
49 },
50 {
51 "id": 2,
52 "email": "ben@example.com",
53 "age": 29
54 },
55 {
56 "id": 3,
57 "email": "not-an-email",
58 "age": -4,
59 "role": "boss"
60 },
61 {
62 "id": "4",
63 "age": 41,
64 "nickname": "cj"
65 }
66 ]
67};
68
69
70const run = await client.actor("ucchiii/json-schema-validator").call(input);
71
72
73console.log('Results from dataset');
74console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
75const { items } = await client.dataset(run.defaultDatasetId).listItems();
76items.forEach((item) => {
77 console.dir(item);
78});
79
80