🛠️DevTools

Package.json Viewer

Navigate through a package.json file to find dependencies, scripts, and configuration.

Code Examples

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

1// Parse and traverse JSON
2const jsonData = {
3 "name": "my-project",
4 "version": "1.0.0",
5 "description": "A sample project",
6 "main": "index.js",
7 "scripts": {
8 "dev": "next dev",
9 "build": "next build",
10 "start": "next start",
11 "test": "jest"
12 },
13 "dependencies": {
14 "react": "^18.2.0",
15 "next": "^14.0.0",
16 "typescript": "^5.0.0"
17 },
18 "devDependencies": {
19 "@types/node": "^20.0.0",
20 "@types/react": "^18.2.0",
21 "eslint": "^8.0.0"
22 }
23};
24
25// Access nested values
26function getValue(obj, path) {
27 return path.split('.').reduce((acc, key) => acc?.[key], obj);
28}
29
30// Get all paths in JSON
31function getAllPaths(obj, prefix = '') {
32 const paths = [];
33 for (const [key, value] of Object.entries(obj)) {
34 const path = prefix ? `${prefix}.${key}` : key;
35 paths.push(path);
36 if (typeof value === 'object' && value !== null) {
37 paths.push(...getAllPaths(value, path));
38 }
39 }
40 return paths;
41}
42
43console.log(getAllPaths(jsonData));

More JSON Examples

Related JSON Tools

📚 Learn More