question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Looping over array from captured

See original GitHub issue
- get:
      url: "/getAllFilesOfUser/{{ username }}"
      headers:
        Accept: "application/json"
        Authorization: "Bearer {{ token }}"
      capture:
        - json: "$.length"
          as: "questionnairesCount"
        - json: "$.*.content"
          as: "questionnaires"
- log: "Received {{ questionnairesCount }} questionnaires for {{ username }}"
# - log: "BLA BLA {{ questionnaires }}"
- loop:
  - log: "LOOP {{ $loopElement }}"
  over: "questionnaires"

The over clause, I couldn’t get it to work with neither questionnaires, "questionnaires" or {{ questionnaires }}

The expected results is pretty obvious.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
gioraguttcommented, Oct 25, 2017

This was indeed a problem on my side. I couldn’t extract the array from the json via simple capture, but after using a JS processor, it iterates fine.

Thanks for the help!

0reactions
gioraguttcommented, Oct 25, 2017

I’m starting to believe that this is a matter of capture syntax.

I have an array of the following structure:

[
{
    "foo": ...,
    "bar": ...,
    "content"....
},
...
]

And I’m trying to get the content item from all of them. I’ve tried $..*.content, $..content, $..*.content, $..[*].content, and so on. I just get the first item, regardless of if there are any more.

But if I have a

capture:
  - json: "$"
    as: "body"

I can see the more than one element in the array, aka [{...}, {...}, ...]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Loop through an array in JavaScript - Stack Overflow
2. Using forEach loop. forEach loop is a modern way to loop through the array. Also, it gives more flexibility and control over...
Read more >
Looping Over Array in Go | TutorialEdge.net
In this snippet, we are going to look at how you can quickly loop over an array in Go.
Read more >
Looping through arrays in PL/pgSQL | YugabyteDB Docs
Looping over the values in an array without the SLICE keyword. This loop is functionally identical to the FOR var IN loop. However,...
Read more >
6.2. Traversing Arrays with For Loops — AP CSAwesome
You can loop through just some of the elements of an array using a for loop. The following code doubles the first five...
Read more >
Documentation: 15: 43.6. Control Structures - PostgreSQL
Without SLICE , or if SLICE 0 is specified, the loop iterates through individual elements of the array produced by evaluating the expression...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found