npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2026 – Pkg Stats / Ryan Hefner

json-path-to-location

v1.0.4

Published

🎯 Find exact line:column locations of JSON values with precise navigation. Perfect for editors, linters, and debugging tools.

Readme

JSON Path to Location 🎯

npm version License: MIT TypeScript Node.js

πŸ” Find exact line:column locations of JSON values with surgical precision

A powerful command-line tool that parses JSON files while preserving complete location information, then navigates through the structure to pinpoint the exact position of any value. Perfect for editors, linters, debugging tools, and automated workflows.

✨ Key Features

  • 🎯 Precise Location Tracking - Line and column numbers for every JSON token
  • πŸš€ JSON Array Navigation - Structured path input with ["property", 0, "nested"] syntax
  • πŸ”§ Editor Integration Ready - Perfect for VS Code extensions, linters, and IDEs
  • πŸ“¦ Zero Dependencies - Pure TypeScript implementation with no external deps
  • πŸ›‘οΈ Type Safe - Full TypeScript support with comprehensive error handling
  • ⚑ Fast & Lightweight - Efficient parsing with minimal memory footprint
  • πŸ”„ Automation Friendly - Pipe support for scripting and CI/CD workflows
  • 🎨 Developer Experience - Clear error messages and intuitive API

πŸš€ Quick Start

# Install globally
npm install -g json-path-to-location

# Use immediately
echo '["user", "profile", "name"]' | json-path-to-location data.json
# Output: 15:12

πŸ’‘ Use Cases

  • πŸ”§ Editor Extensions: Build precise navigation features
  • πŸ› Debugging Tools: Pinpoint exact error locations
  • πŸ“‹ Linters: Report issues with exact line:column positions
  • πŸ€– Code Generation: Generate source maps and references
  • πŸ“Š Analysis Tools: Navigate large JSON configurations
  • πŸ” Search & Replace: Find and modify specific JSON values

πŸ“¦ Installation

Global Installation

npm install -g json-path-to-location

Programmatic Usage

npm install json-path-to-location
import { JsonParser, JsonNavigator } from 'json-path-to-location';

const parser = new JsonParser(jsonString);
const parsed = parser.parse();
const navigator = new JsonNavigator(parsed.tokens);
const location = navigator.findLocationForPath(parsed.value, ["user", "name"]);
// location: { start: { line: 5, column: 12 }, end: { line: 5, column: 24 } }

🎬 Demo

{
  "users": [
    {
      "name": "Alice",
      "profile": {
        "email": "[email protected]"
      }
    }
  ]
}
# Find Alice's email location
echo '["users", 0, "profile", "email"]' | json-path-to-location users.json
# Output: 6:17

# Find the users array
echo '["users"]' | json-path-to-location users.json  
# Output: 2:12

πŸ”§ API Reference

CLI Usage

json-path-to-location <json-file>

Programmatic API

import { JsonParser, JsonNavigator, LocationInfo } from 'json-path-to-location';

// Parse JSON with location tracking
const parser = new JsonParser(jsonString);
const { value, tokens } = parser.parse();

// Navigate to specific path
const navigator = new JsonNavigator(tokens);
const location: LocationInfo | undefined = navigator.findLocationForPath(
  value, 
  ["users", 0, "name"]
);

console.log(location);
// { start: { line: 4, column: 14 }, end: { line: 4, column: 21 } }

Path Format

Paths are JSON arrays where:

  • Strings navigate object properties: "name", "address"
  • Numbers navigate array indices: 0, 1, 2
  • Mixed for complex navigation: ["users", 0, "profile", "settings", 2]

πŸ“‹ Examples

Basic Usage

# Get location of the root object
echo '[]' | json-path-to-location data.json
# Output: 1:1

# Get location of a property
echo '["name"]' | json-path-to-location data.json
# Output: 2:11

Complex Navigation

# Navigate through objects and arrays
echo '["users", 0, "profile", "email"]' | json-path-to-location data.json
# Output: 8:17

# Array access
echo '["items", 2]' | json-path-to-location data.json
# Output: 12:5

Automation with Pipes

# Batch processing
for path in '["name"]' '["age"]' '["email"]'; do
  echo "$path" | json-path-to-location user.json
done

🚨 Error Handling

# Invalid path
echo '["nonexistent"]' | json-path-to-location data.json
# Error: Path [nonexistent] not found in JSON.

# Invalid format
echo '"not an array"' | json-path-to-location data.json
# Error: Input must be a JSON array

# Invalid types
echo '[true, "test"]' | json-path-to-location data.json
# Error: Array elements must be strings or numbers

⚑ Performance

  • Fast: Parses large JSON files efficiently with O(n) complexity
  • Memory Efficient: Minimal memory overhead for location tracking
  • Zero Dependencies: No external dependencies means faster installs
  • TypeScript Native: Full type safety without runtime overhead

πŸ†š Why This Tool?

| Feature | json-path-to-location | Standard JSON.parse | JSONPath libraries | |---------|----------------------|--------------------|--------------------| | πŸ“ Location tracking | βœ… Line:column precision | ❌ No location info | ❌ No location info | | 🎯 Exact positioning | βœ… Character-level accuracy | ❌ Not available | ❌ Not available | | πŸ”§ Editor integration | βœ… Perfect for IDEs | ❌ Not suitable | ❌ Limited | | πŸš€ Zero dependencies | βœ… Lightweight | βœ… Built-in | ❌ Heavy deps | | πŸ“¦ CLI + Library | βœ… Both included | ❌ Parse only | ❌ Library only |

πŸ“Š Type Support

The application correctly handles all JSON types:

  • Objects: Navigate using property names
  • Arrays: Navigate using numeric indices (0-based)
  • Strings: Terminal values with location tracking
  • Numbers: Terminal values with location tracking (integers and floats)
  • Booleans: Terminal values with location tracking (true or false)
  • Null: Terminal values with location tracking

πŸ› οΈ Development

Build

npm run build

Test

npm test
# or
./test.sh

The test suite includes 29 comprehensive tests covering:

  • βœ… Basic navigation (root, properties, different data types)
  • βœ… Nested object navigation
  • βœ… Array navigation with numeric indices
  • βœ… Complex mixed navigation (arrays containing objects)
  • βœ… Error handling (non-existent paths, invalid operations)
  • βœ… JSON format validation (invalid syntax, non-arrays, invalid element types)
  • βœ… Edge cases and number parsing

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Run tests (npm test)
  4. Commit your changes (git commit -m 'Add amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a Pull Request

πŸ“„ License

MIT Β© 2025