Combining JSON data from seperate sources

Options

Hi,

I have a table of products and each product gets dynamically priced for the individual user in real time. The price is retrieved from an API call. I'm trying figure out how I can combine the products and the price data into a single JSON response that I can use as an API call.

I have attached a screenshot to try and best illustrate what I'm asking to accomplish.

Comments

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    Hi,

    Are those lists in a right order and of the same length?

    If yes then what I would do is create an empty array variable then run a loop and create array remove from the end/beginning for both lists then you are getting the removed elements and using update variable you can add the price to the object from the product list and afterward you are appending this new object to the empty list from the beginning. And then the loop is going for another round.

  • mikhaeel
    mikhaeel Member
    Options

    Hey @Pawel Magdanski, thanks for your reply. The lists are in the right order and the same length. My concern with the method you described is that perhaps for large lists (100+ items) this could become inefficient and slow?

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    Hi @mikhaeel I think for 100+ it should be reasonable in regards to time. But if the number of elements in the list will be much bigger than that then yes, that might be a problem.

    I can't think of a way to do this as a bulk and merge all objects from both lists at the same time.

  • mikhaeel
    mikhaeel Member
    Options

    @Pawel Magdanski I'll give this a shot and see how it goes. I appreciate your help!