Help Needed: Extracting Values from Nested JSON with Varying Index Positions in Xano

Hi everyone,

I’m working with XML data in Xano that I’ve decoded into JSON using xml_decode. The JSON contains both top-level attributes and nested objects. My goal is to loop through each item and extract key values from both the top level and nested structures. For example, I can easily get values like cruiseid and cruisename from the top level using dot notation (e.g., [email protected]), and it works perfectly for these straightforward cases.

However, I’m encountering an issue with nested objects, especially when the same object (e.g., line) changes its position within the array in each cruise object.

For instance, I need to extract [email protected] in the loop. In one item, I can access it using [email protected], but in other items, the line object is at index 7 or even 8. Since the index is not consistent, it breaks the loop.

What I’ve Tried:

  1. Dot Notation: Using response_item.cruise.value[3][email protected] works for some items, but breaks when the line object is at a different index.

  2. Finding Elements: I’ve tried using Xano’s "Find Element" and "Find Object by Key" functions, but they still seem to rely on the index position when setting the subpath, which isn’t reliable in my case.

  3. Lambda Functions: I attempted to solve this issue with Lambda functions by iterating through the array to find the line object by key (id), but I haven’t been able to get this working as expected.

What I’m Looking For:

I need an efficient way to dynamically search for the line object by name, regardless of its position in the value array, and extract the id attribute from line.@attributes. Essentially, I’m trying to implement logic that looks for the line object wherever it exists in the array and retrieves the id without relying on the index position.

Is there a method or workaround in Xano to achieve this? How can I dynamically extract nested values in a loop without depending on the index? Any help with this, especially on how to structure it efficiently, would be greatly appreciated!

Thanks in advance!

4 replies