You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -19,33 +19,41 @@ The `/json` endpoint extracts structured data from a webpage. You can specify th
19
19
20
20
### With a Prompt and JSON schema
21
21
22
-
This example captures webpage data by providing both a prompt and a JSON schema. If multiple headings exist, the first occurrence of each (such as `h1`, `h2`) is returned.
22
+
This example captures webpage data by providing both a prompt and a JSON schema. The prompt guides the extraction process, while the JSON schema defines the expected structure of the output.
23
23
24
24
```bash
25
25
curl --request POST 'https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID/browser-rendering/json' \
26
26
--header 'authorization: Bearer CF_API_TOKEN' \
27
27
--header 'content-type: application/json' \
28
28
--data '{
29
-
"url": "http://demoto.xyz/headings",
30
-
"prompt": "Get the heading from the page. If there are many then grab the first one.",
31
-
"response_format": {
32
-
"type": "json_schema",
33
-
"json_schema": {
29
+
"url": "https://developers.cloudflare.com/",
30
+
"prompt": "Get me the list of AI products",
31
+
"response_format": {
32
+
"type": "json_schema",
33
+
"json_schema": {
34
34
"type": "object",
35
35
"properties": {
36
-
"h1": {
37
-
"type": "string"
38
-
},
39
-
"h2": {
40
-
"type": "string"
36
+
"products": {
37
+
"type": "array",
38
+
"items": {
39
+
"type": "object",
40
+
"properties": {
41
+
"name": {
42
+
"type": "string"
43
+
},
44
+
"link": {
45
+
"type": "string"
46
+
}
47
+
},
48
+
"required": [
49
+
"name"
50
+
]
51
+
}
41
52
}
42
-
},
43
-
"required": [
44
-
"h1"
45
-
]
53
+
}
46
54
}
47
-
}
48
-
}'
55
+
}
56
+
}'
49
57
```
50
58
51
59
#### JSON response
@@ -54,23 +62,44 @@ curl --request POST 'https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID
In this example, only a prompt is provided. The endpoint will use the prompt to extract the heading information from the page.
93
+
In this example, only a prompt is provided. The endpoint will use the prompt to extract the data, but the response will not be structured according to a JSON schema.
94
+
This is useful for simple extractions where you don't need a specific format.
66
95
67
96
```bash
68
97
curl --request POST 'https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID/browser-rendering/json' \
69
98
--header 'authorization: Bearer CF_API_TOKEN' \
70
99
--header 'content-type: application/json' \
71
100
--data '{
72
-
"url": "http://demoto.xyz/headings",
73
-
"prompt": "Get the heading from the page in the form of an object like h1, h2. If there are many headings of the same kind then grab the first one."
101
+
"url": "https://developers.cloudflare.com/",
102
+
"prompt": "get me the list of AI products"
74
103
}'
75
104
```
76
105
@@ -80,8 +109,13 @@ curl --request POST 'https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID
80
109
{
81
110
"success": true,
82
111
"result": {
83
-
"h1": "Heading 1",
84
-
"h2": "Heading 2"
112
+
"AI Products": [
113
+
"Build a RAG app",
114
+
"Workers AI",
115
+
"Vectorize",
116
+
"AI Gateway",
117
+
"AI Playground"
118
+
]
85
119
}
86
120
}
87
121
```
@@ -94,25 +128,30 @@ In this case, you supply a JSON schema via the `response_format` parameter. The
94
128
curl --request POST 'https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID/browser-rendering/json' \
95
129
--header 'authorization: Bearer CF_API_TOKEN' \
96
130
--header 'content-type: application/json' \
97
-
--data '{
98
-
"url": "http://demoto.xyz/headings",
99
-
"response_format": {
100
-
"type": "json_schema",
101
-
"json_schema": {
131
+
--data '"response_format": {
132
+
"type": "json_schema",
133
+
"json_schema": {
102
134
"type": "object",
103
135
"properties": {
104
-
"h1": {
105
-
"type": "string"
106
-
},
107
-
"h2": {
108
-
"type": "string"
136
+
"products": {
137
+
"type": "array",
138
+
"items": {
139
+
"type": "object",
140
+
"properties": {
141
+
"name": {
142
+
"type": "string"
143
+
},
144
+
"link": {
145
+
"type": "string"
146
+
}
147
+
},
148
+
"required": [
149
+
"name"
150
+
]
151
+
}
109
152
}
110
-
},
111
-
"required": [
112
-
"h1"
113
-
]
153
+
}
114
154
}
115
-
}
116
155
}'
117
156
```
118
157
@@ -122,14 +161,68 @@ curl --request POST 'https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID
1.**Extract movie data:** Retrieve details like name, genre, and release date for the top 10 action movies from the IMDB top 250 list by supplying the appropriate IMDB link and JSON schema.
134
-
2.**Weather information:** Fetch current weather conditions for a location (such as., Edinburgh) using a weather website link (like from BBC Weather).
135
-
3.**Trending news:** Extract top trending posts on Hacker News by providing the Hacker News link along with a JSON schema that includes post title and body.
0 commit comments