🛠️DevTools

Paginated API Response

This example demonstrates viewing array data and pagination metadata from a typical REST API response.

Code Examples

Here's how to achieve this in different programming languages:

1// Parse and traverse JSON
2const jsonData = {
3 "data": {
4 "items": [
5 {
6 "id": 1,
7 "name": "Item 1",
8 "status": "active"
9 },
10 {
11 "id": 2,
12 "name": "Item 2",
13 "status": "pending"
14 },
15 {
16 "id": 3,
17 "name": "Item 3",
18 "status": "active"
19 }
20 ],
21 "pagination": {
22 "page": 1,
23 "perPage": 10,
24 "total": 100,
25 "totalPages": 10
26 }
27 },
28 "meta": {
29 "requestId": "abc-123",
30 "timestamp": "2024-01-15T10:30:00Z"
31 }
32};
33
34// Access nested values
35function getValue(obj, path) {
36 return path.split('.').reduce((acc, key) => acc?.[key], obj);
37}
38
39// Get all paths in JSON
40function getAllPaths(obj, prefix = '') {
41 const paths = [];
42 for (const [key, value] of Object.entries(obj)) {
43 const path = prefix ? `${prefix}.${key}` : key;
44 paths.push(path);
45 if (typeof value === 'object' && value !== null) {
46 paths.push(...getAllPaths(value, path));
47 }
48 }
49 return paths;
50}
51
52console.log(getAllPaths(jsonData));

More JSON Examples

Related JSON Tools

📚 Learn More