How can I use search results data in my liquid logic?

Good morning,
I’m trying to insert my search result, returned by search.results, into a JSON.
I researched some topics and tried some solutions but I am not able to use the returned data.
So far, I have the result inside an array but I’m not able to use the information returned in my search.liquid.

I can see the product data in console.log, but I don’t know how to use this data inside the liquid.
For example, if I only wanted to display the product.title of each product on the screen, how to proceed inside the liquid? How to connect the productsData variable with my liquid logic? I tried using {%assign%} but couldn’t se any information.

Thanks

@FMS-DEV

As far as I am aware, it wouldn’t be possible to convert a JSON to Liquid.

In your case I see two potential solutions:

  1. Populate the items using Javascript instead of liquid. This is a very crude example, but you get the idea:
const products = [{name: "a"}, {name: "b"}]
const $el = document.querySelector(`#CustomProducts`);

let html = '';

for (const each of products){
html += `## ${each.name}
`;
}

$el.insertAdjacentHTML('afterbegin', html);
  1. Don’t build a JSON at all and straight up populate the liquid within the {% for %}. You can loop through the search results and not use Javascript at all.

Kind regards,
Diego