🛠️DevTools

MongoDB Document Viewer

Explore MongoDB documents with their extended JSON types like $oid and $date.

Code Examples

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

1// Parse and traverse JSON
2const jsonData = {
3 "_id": {
4 "$oid": "507f1f77bcf86cd799439011"
5 },
6 "orderNumber": "ORD-2024-001",
7 "customer": {
8 "_id": {
9 "$oid": "507f1f77bcf86cd799439022"
10 },
11 "name": "Jane Smith",
12 "email": "jane@example.com",
13 "address": {
14 "street": "456 Oak Avenue",
15 "city": "San Francisco",
16 "state": "CA",
17 "zip": "94102"
18 }
19 },
20 "items": [
21 {
22 "productId": {
23 "$oid": "507f1f77bcf86cd799439033"
24 },
25 "name": "Wireless Keyboard",
26 "quantity": 2,
27 "price": 79.99
28 },
29 {
30 "productId": {
31 "$oid": "507f1f77bcf86cd799439044"
32 },
33 "name": "USB-C Hub",
34 "quantity": 1,
35 "price": 49.99
36 }
37 ],
38 "totals": {
39 "subtotal": 209.97,
40 "tax": 18.9,
41 "shipping": 9.99,
42 "total": 238.86
43 },
44 "status": "shipped",
45 "createdAt": {
46 "$date": "2024-01-15T10:30:00Z"
47 },
48 "updatedAt": {
49 "$date": "2024-01-16T14:22:00Z"
50 }
51};
52
53// Access nested values
54function getValue(obj, path) {
55 return path.split('.').reduce((acc, key) => acc?.[key], obj);
56}
57
58// Get all paths in JSON
59function getAllPaths(obj, prefix = '') {
60 const paths = [];
61 for (const [key, value] of Object.entries(obj)) {
62 const path = prefix ? `${prefix}.${key}` : key;
63 paths.push(path);
64 if (typeof value === 'object' && value !== null) {
65 paths.push(...getAllPaths(value, path));
66 }
67 }
68 return paths;
69}
70
71console.log(getAllPaths(jsonData));

More JSON Examples

Related JSON Tools

📚 Learn More