Retrieving element name from JSON Message

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
Eugene
Posts: 8
Joined: Sat Apr 22, 2017 12:01 am

Retrieving element name from JSON Message

Post by Eugene » Thu Jun 13, 2019 11:32 pm

Is there a way to retrieve the element name from a JSON message as well as the value?
I'm using the URL below to retrieve a list of the exchange rates. I now want to read through the returned JSON message and not only retrieve the value but also the element (key) name.

https://api.exchangeratesapi.io/latest

{
base: "EUR",
rates: {
BGN: 1.9558,
NZD: 1.7206,
ILS: 4.0544,
RUB: 73.0227,
CAD: 1.5002,
USD: 1.132,
},
date: "2019-06-11"
}

Thanks in advance.
Eugene

tsupartono
Posts: 65
Joined: Wed Jan 25, 2017 11:12 am

Re: Retrieving element name from JSON Message

Post by tsupartono » Fri Jun 14, 2019 4:38 pm

I'm assuming you are going to do this on your server-side code (server module).
The best way right now is to use PRIM_JSON.Reader
See https://apps.lansa.com/lansav14sp2/dem/xdemow_12.html for usage example.

Have a look at this forum post as well:
viewtopic.php?f=3&t=2046#p5374

While using PRIM_JSON.Reader is not the most straightforward thing to do, it would be the best solution for now until EPC142060 is released - after which you can use PRIM_JSON.Document, which is much easier to use (currently there are issues getting decimal values using PRIM_JSON.Document).

If this is just for demonstration, you can also do it client side using a widget.

Post Reply