How to create a new json object based on dynamic values from a DB query?

I am querying my database for an array of products, in my example the results are 2 products. It looks like this:

"query_products": [
    {
      "id": 24,
      "name": "Ebook",
      "description": "Ebook product",
      "original_price": 300,
      "current_price": 200,
      "list_order": null,
      "order_bump": null,
      "deleted": null,
      "mj_property_id": 23558,
      "mj_property_value": "ispurchased"
    },
    {
      "id": 25,
      "name": "audiobook",
      "description": "",
      "original_price": 200,
      "current_price": 100,
      "list_order": null,
      "order_bump": 1,
      "deleted": null,
      "mj_property_id": 23559,
      "mj_property_value": "ispurchased"
    }
  ]

Now I want to create a new JSON object based on these 2 objects (it can be any number or objects!), it should look like this:

{
  "Data": [
    {
      "Name": "23558",
      "Value": "ispurchased"
    },
    {
      "Name": "23559",
      "Value": "ispurchased"
    }
  ]
}

( I’m taking the mj_property_id and mj_property_value )

Context: I need to send this JSON data to another API using ‘API action’:

Community Page
Last updated: