The getDeltaByPath
method is a tool of jsondiffpatch utility designed to extract a specific delta (change set) from a larger delta object representing differences between two JSON objects. This method is useful for retrieving precise change information at a given path within the JSON structure.
AddedDelta
: Represents an added value.ModifiedDelta
: Represents a change from one value to another.DeletedDelta
: Represents a deleted value.ObjectDelta
: A complex object structure representing changes in a nested JSON object.ArrayDelta
: Represents changes in an array, including additions, deletions, and modifications.MovedDelta
: Represents a moved value within an array.TextDiffDelta
: Represents a textual difference.delta
: The root delta object from which changes are extracted.path
: The path to the specific change within the delta object. It can be a string or an array of strings representing the path to the desired change.Returns a Delta object representing the change at the specified path. If no change exists at that path or the path is invalid, the function returns undefined.
To use the getDeltaByPath
function, you need to pass the complete delta object and the path to the specific change you want to retrieve. The path can be a dot-separated string (e.g., "user.name"
) or an array of strings representing the keys and indexes in the path (e.g., ["user", "name"]
).
ArrayDelta
and ObjectDelta
, the function recursively searches for the specified path.AddedDelta
, ModifiedDelta
, and DeletedDelta
, it directly returns the corresponding change if it matches the path.The getDeltaByPath
method is a powerful tool for navigating complex delta objects and extracting specific changes, making it easier to understand and handle the differences between JSON objects in a fine-grained manner.