Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions lua/jsonpath.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,19 @@ M.get = function(start_node, bufnr)
end

if node:type() == "array" then
accessor = "[]"

for i, child in ipairs(get_children(node)) do
local parent = current_node:parent()
if parent == child then
accessor = string.format("[%d]", i - 1)
local index = 0
for child in node:iter_children() do
if child:named() then
local n = current_node
while n and n ~= node do
if n == child then
accessor = string.format("[%d]", index)
break
end
n = n:parent()
end
if accessor ~= "" then break end
index = index + 1
end
end
end
Expand Down