π 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.
- π― 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
# Install globally
npm install -g json-path-to-location
# Use immediately
echo '["user", "profile", "name"]' | json-path-to-location data.json
# Output: 15:12- π§ 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
npm install -g json-path-to-locationnpm install json-path-to-locationimport { 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 } }{
"users": [
{
"name": "Alice",
"profile": {
"email": "alice@example.com"
}
}
]
}# 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:12json-path-to-location <json-file>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 } }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]
# 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# 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# Batch processing
for path in '["name"]' '["age"]' '["email"]'; do
echo "$path" | json-path-to-location user.json
done# 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- 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
| 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 |
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 (
trueorfalse) - Null: Terminal values with location tracking
npm run buildnpm test
# or
./test.shThe 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
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Run tests (
npm test) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT Β© 2025