🛠️DevTools

User Profile JSON

This example shows how the viewer handles nested objects like user profiles with multiple levels of data.

Code Examples

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

1// Parse and traverse JSON
2const jsonData = {
3 "user": {
4 "id": 12345,
5 "name": "John Doe",
6 "email": "john@example.com",
7 "profile": {
8 "avatar": "https://example.com/avatar.jpg",
9 "bio": "Software developer",
10 "social": {
11 "twitter": "@johndoe",
12 "github": "johndoe"
13 }
14 },
15 "settings": {
16 "theme": "dark",
17 "notifications": true
18 }
19 }
20};
21
22// Access nested values
23function getValue(obj, path) {
24 return path.split('.').reduce((acc, key) => acc?.[key], obj);
25}
26
27// Get all paths in JSON
28function getAllPaths(obj, prefix = '') {
29 const paths = [];
30 for (const [key, value] of Object.entries(obj)) {
31 const path = prefix ? `${prefix}.${key}` : key;
32 paths.push(path);
33 if (typeof value === 'object' && value !== null) {
34 paths.push(...getAllPaths(value, path));
35 }
36 }
37 return paths;
38}
39
40console.log(getAllPaths(jsonData));

More JSON Examples

Related JSON Tools

📚 Learn More