Query json

Hi community!
I need help!
I have this input JSON

{
  "discounts": {
    "PG1": 0.25,
    "PG2": 0.05
  },
  "prices": [
    {
      "goodsArticle": "TEST1",
      "priceGroup": "PG1",
      "price": 100
    }
  ]
}

I need this result

[
  {
    "goodsArticle": "TEST1",
    "priceGroup": "PG1",
    "price": 100,
    "discount": 0.25
  }
]

I tried several(tons) of tricks like

prices.{
  "goodsArticle": goodsArticle,
  "priceGroup": priceGroup,
  "price": price,
  "discount": discounts[priceGroup]
}

And

prices.{
  "goodsArticle": goodsArticle,
  "priceGroup": priceGroup,
  "price": price,
  "discount": $lookup(discounts, priceGroup)
}

But can’t force it to work. Every time Query JSON returned me

{
  "goodsArticle": "TEST1",
  "priceGroup": "PG1",
  "price": 100
}

i.e. without “discount”:
Thanks!

Hey, we got a winner.
Tell AI that it’s a dirty liar often enough, it will eventually give you the correct answer. Try this.

prices.{
  "goodsArticle": goodsArticle,
  "priceGroup": priceGroup,
  "price": price,
  "discount": $lookup($$.discounts, priceGroup)
}
3 Likes

Thank you very much, Jeff!
Million thanks! :pray:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.