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.

Random number of entries in payload

See original GitHub issue

Hi I would be nice if it was possible to randomize the number of entries in the payload. An example could be orders with a random number of order lines.

Let’s say I have some orders:

   payload:
      - path: "orders.csv"
        fields:
          - "order_number"
          - "first_name"
          - "last_name"

… and some lines:

   payload:
      - path: "order-lines.csv"
        fields:
          - "product_number"
          - "price"
          - "quantity"

Then it would be nice to be able to randomize the number of order lines, eg. like this:

json:
   order_number: "{{ order_number }}"
   first_name:   "{{ first_name }}"
   last_name:    "{{ last_name }}"
   lines:
     random-array:
       min: 1
       max: 5
       product_number: "{{ product_number }}"
       price:          "{{ price }}"
       quantity:       "{{ quantity }}"          

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
erasmussenBHTPcommented, May 30, 2019

Here is what I’m doing for my workaround. There is a possibility of duplicates with this approach. I’m working with a large input CSV and my system needs to be able to handle duplicates.

payload:
    -
      path: 'flights.csv'
      skipHeader: true
      fields:
        - 'airline0'
        - 'flightNumber0'
        - 'depAirport0'
        - 'arrAirport0'
    -
      path: 'flights.csv'
      skipHeader: true
      fields:
        - 'airline1'
        - 'flightNumber1'
        - 'depAirport1'
        - 'arrAirport1'
    -
      path: 'flights.csv'
      skipHeader: true
      fields:
        - 'airline2'
        - 'flightNumber2'
        - 'depAirport2'
        - 'arrAirport2'
    -
      path: 'flights.csv'
      skipHeader: true
      fields:
        - 'airline3'
        - 'flightNumber3'
        - 'depAirport3'
        - 'arrAirport3'

My beforeRequest javascript does the following

function setJSONBody(requestParams, context, ee, next) {
    const flightCount = Math.floor(Math.random() * (3)) + 1;
    for (let i = 0; i < flightCount; i++) {
        requestParams.json.flights.push({
            'flightDesignator': `{{ airline${i} }}{{ flightNumber${i} }}`,
            'departureAirportCode': `{{ depAirport${i} }}`,
            'arrivalAirportCode': `{{ arrAirport${i} }}`,
            'departureDate': moment().add(i > 1 ? 4 : 3, 'days').format('YYYY-MM-DD')
        });
    }
    
    return next();
}
0reactions
hassycommented, May 31, 2019

Thanks for sharing that @erasmussenBHTP, that’s very helpful! We’ll need to size up the effort of adding support for tags/functions that operate on the node itself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generating random number inside json file - Stack Overflow
I want to give a random number in json file which is payload for the API post request. The "ssn" value in json...
Read more >
Random Number Node - Losant Documentation
The Random Number Node generates a random integer within a range of your choosing.
Read more >
How can I generate a random value but limited between two ...
How can I generate a random value but limited between two values such as a value between ... ReservoirCapacity = parseInt(Math.random() * 25);...
Read more >
Generate a random number in Dataweave
Could you guys help me in generating a random number, ... [CDATA[%dw 1.0; %output application/xml; ---; rows: {(payload.rows.
Read more >
How to do a random number bruteforce in burp suite?
I want to do a bruteforce from number 38000000000 to 39000000000 but what is happening here, when I try to bruteforce with Payload...
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