NAME

JSON::Structure::JsonSourceLocator - Track line and column positions in JSON documents

SYNOPSIS

use JSON::Structure::JsonSourceLocator;

my $locator = JSON::Structure::JsonSourceLocator->new($json_text);
my $location = $locator->get_location('#/properties/name');

if ($location->is_known) {
    say "Found at line $location->{line}, column $location->{column}";
}

DESCRIPTION

This module tracks line and column positions in a JSON document and maps JSON Pointer paths to source locations. It parses the JSON text to build a map of paths to character offsets, then converts offsets to line/column positions.

Limitations: This is a lightweight, hand-rolled JSON path locator optimized for typical JSON Structure schemas. It may report incorrect positions for:

  • Complex escape sequences in strings (e.g., \uXXXX surrogate pairs)

  • Deeply nested structures with many embedded strings containing braces/brackets

  • Non-standard "relaxed" JSON (comments, trailing commas, unquoted keys)

  • Very large documents where character-by-character parsing is slow

For production use requiring precise positions in complex JSON, consider using a streaming tokenizer like JSON::Streaming::Reader or JSON::SL that can report byte offsets during parsing.

get_location($path)

Returns a JsonLocation object for the given JSON Pointer path.

my $location = $locator->get_location('#/properties/name');

AUTHOR

JSON Structure Project

LICENSE

MIT License