Skip to content

Conversation

@majiayu000
Copy link

Fixes #18145

Changes

  • Convert JSON to CBOR internally and use cborquery for array-aware XPath parsing
  • Update tests and configs for new array syntax (use //array[1] instead of //array/*[1])
  • Add test case for JSON array indexing

Breaking Changes

  • Array selection: Use //array instead of //array/* to select elements
  • String representation of objects/arrays may differ from pure JSON format

The xpath_json parser previously failed to correctly parse JSON array
elements using XPath expressions like //array[1]/field. This was because
the underlying jsonquery library treats arrays as single container nodes
with unnamed children, making it impossible to index into arrays directly.

This change modifies the JSON document handler to:
- Convert JSON to CBOR format internally
- Use cborquery for parsing, which correctly handles array elements as
  named siblings that can be indexed with XPath expressions

The fix enables users to access JSON array elements using intuitive XPath
syntax like //nvme_namespaces[1]/capacity/bytes instead of requiring the
workaround //*[local-name()='nvme_namespaces']/*[1]/capacity/bytes.

Note: This is a breaking change for some XPath query patterns:
- Array selection: Use //array instead of //array/* to select elements
- String representation of objects/arrays differs from JSON format

Fixes influxdata#18145

Signed-off-by: majiayu000 <[email protected]>
@telegraf-tiger
Copy link
Contributor

telegraf-tiger bot commented Jan 2, 2026

Thanks so much for the pull request!
🤝 ✒️ Just a reminder that the CLA has not yet been signed, and we'll need it before merging. Please sign the CLA when you get a chance, then post a comment here saying !signed-cla

@telegraf-tiger telegraf-tiger bot added the fix pr to fix corresponding bug label Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix pr to fix corresponding bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

xpath fails to parse json array elements

1 participant