Conversion of json response from api call to csv for excel - json

I have received a json response from an api call and now I want to convert it to csv format with specified column names from my response message. But now I'm getting an error message while trying to validate my json response. I am pasting a sample of my json response:
{"fields":[{"name":"tenant_name","fieldType":"string","keyField"
0046: :true},{"name":"app","fieldType":"string","keyField":true},{"nam
0086: e":"_count","fieldType":"int","keyField":false}],"records":[{"ma
00c6: p":{"app":"[WhatsApp] numbytes 608","tenant_name":"ABC","_c
0106: ount":"1"}},{"map":{"app":"[Workplace by Facebook - Alpha] nu
0146: mbytes unknown","tenant_name":"ABC alpha","_count":"4"}},{"ma
0186: p":{"app":"google numbytes 3029","tenant_name":"k2 intelligence"
01c6: ,"_count":"1"}},{"map":{"app":"onesna zang numbytes 21257","tena
0206: nt_name":"ePlus Technologies Corporate","_count":"1"}},{"map":{"
0246: app":"eQuest numbytes 366","tenant_name":"ePlus Technologies Cor
0286: porate","_count":"1"}},{"map":{"app":"Yahoo Developer Network nu
02c6: mbytes 6272","tenant_name":"ePlus Technologies Corporate","_coun
0306: t":"1"}},{"map":{"app":"Yahoo Developer Network numbytes 54078",
0346: "tenant_name":"ePlus Technologies Corporate","_count":"1"}},
The csv which I'm looking for should be having tenant_name and app as the two columns from this response json. I thing there's an issue with my json formatting. Any idea on how to make it work? I am trying with https://jsonlint.com/ but there's so many errors I am getting.

Related

Microsoft Azure iot-hub: The measured senosor values sent via device to iot-hub cannot be read stored Json data

We are using a data acquisition system as a device and send some signals values via MQTT protocol into a container which is assigned to an iot-hub. The connection works well between device and iot-hub, and we receive some JSON data. When we open a JSON data, We cannot read the temperature values in "Body" inside the JSON data, since they are encoded. I would be thankful if you tell us, how we should automatically convert the JSON data to a proper format so that we could read the values in numbers?
Please find below three of our code's lines in JSON Data. The rest of the lines are the same, but they are encoded differently.
{"EnqueuedTimeUtc":"2022-02-09T10:00:30.8600000Z","Properties":{"Sensor":""},"SystemProperties":{"connectionDeviceId":"Iba","connectionAuthMethod":"{"scope":"device","type":"sas","issuer":"iothub","acceptingIpFilterRule":null}","connectionDeviceGenerationId":"637799949903534194","enqueuedTime":"2022-02-09T10:00:30.8600000Z"},"Body":"My42MjI3NTQ="}
{"EnqueuedTimeUtc":"2022-02-09T10:00:30.8750000Z","Properties":{"Sensor":""},"SystemProperties":{"connectionDeviceId":"Iba","connectionAuthMethod":"{"scope":"device","type":"sas","issuer":"iothub","acceptingIpFilterRule":null}","connectionDeviceGenerationId":"637799949903534194","enqueuedTime":"2022-02-09T10:00:30.8750000Z"},"Body":"My42ODEyNDY="}
{"EnqueuedTimeUtc":"2022-02-09T10:00:30.9070000Z","Properties":{"Sensor":""},"SystemProperties":{"connectionDeviceId":"Iba","connectionAuthMethod":"{"scope":"device","type":"sas","issuer":"iothub","acceptingIpFilterRule":null}","connectionDeviceGenerationId":"637799949903534194","enqueuedTime":"2022-02-09T10:00:30.9070000Z"},"Body":"My43Mzk1OTI="}
Thanks in advance!
Br
Masoud
you should add to the message topic two parameters such as the content-type (ct) and content-encoding (ce) like is shown in the following example:
devices/device1/messages/events/$.ct=application%2Fjson&$.ce=utf-8

Can the Azure Storage REST API send the response in JSON format?

I am developing a library for working with various types of cloud based queue services.
One of those services is the Azure Queue Storage REST API.
For the Amazon SQS service I can send an Accept: application/json header and the response is in JSON format.
Since JSON is a format that is supported by many APIs and XML is not fun to work with, I would prefer the Azure Storage REST API to also return a response in JSON format.
I have tried to set the Accept: application/json header to no avail. The responses are all in XML format with Content-Type: application/xml, which is obviously not what I was asking for.
Currently all code is in C with dependencies on a couple of libraries, including cURL and jansson, although for this question that doesn't really matter. It's just that I would like the library to be as simple and lightweight as possible.
I have a hard time digging through all kinds of documentation. Most topics I can find are about sending JSON within a message. But that's not what I'm going for.
Is it even possible to receive the actual responses in JSON? I would really like to drop my libxml2 dependency.
As pointed by #Tom Because the documentation is stating that it only return XML, I would personally write an azure function who becomes an adaptor which basically takes your request, sends it to azure queue storage, retrieves the xml response and then converts the xml response to json and return the json to the caller (which will be your C code).
A sample python code to convert xml to json is shown below:
import xmltodict
import json
text = ''
xpars = xmltodict.parse(text)
json = json.dumps(xpars)
print(json)
A sample xml message
text = '<QueueMessagesList>
<QueueMessage>
<MessageId>string-message-id</MessageId>
<InsertionTime>insertion-time</InsertionTime>
<ExpirationTime>expiration-time</ExpirationTime>
<PopReceipt>opaque-string-receipt-data</PopReceipt>
<TimeNextVisible>time-next-visible</TimeNextVisible>
<DequeueCount>integer</DequeueCount>
<MessageText>message-body</MessageText>
</QueueMessage>
</QueueMessagesList>'
And the response will be :
{
"QueueMessagesList": {
"QueueMessage": {
"MessageId": "string-message-id",
"InsertionTime": "insertion-time",
"ExpirationTime": "expiration-time",
"PopReceipt": "opaque-string-receipt-data",
"TimeNextVisible": "time-next-visible",
"DequeueCount": "integer",
"MessageText": "message-body"
}
}
}
Please Note: This whole thing can also be done using a Logic App in azure.
I have only shown the XML to JSON converter part here, but it is really straightforward to write an HTTP Trigger Azure Function to do the same. Or you can even write this converter into your C code as well.
Hope this helps you in moving on with your library development.

How to parse or deserialze JSON String which is a response to REST API call in Automation Anywhere?

In Automation Anywhere, how to we parse a json string which is response to the REST API call?
Unlike UiPath, AA does not seem to have a deserialize option for JSON String.
My aim here is to extract "item" details from the "searchResult" element.
Please help.
Below is my json string:
[{"findItemsByKeywordsResponse":\[{"ack":\["Success"\],"version":\["1.13.0"\],"timestamp":\["2018-08-06T19:30:50.830Z"\],"searchResult":\[{"#count":"2","item":\[{"itemId":\["253482447437"\],"title":\["*Sealed in Box* Verizon Apple iPhone SE 16/64GB 4.0\" Unlocked Smartphone"\],"globalId":\["EBAY-US"\],"subtitle":\["NO-RUSH 14 DAYS SHIPPING ONLY! US LOCATION!"\],"primaryCategory":\[{"categoryId":\["9355"\],"categoryName":\["Cell Phones & Smartphones"\]}\],"galleryURL":\["http://thumbs2.ebaystatic.com/pict/253482447437404000000004_1.jpg"\],"viewItemURL":\["http://www.ebay.com/itm/Sealed-Box-Verizon-Apple-iPhone-SE-16-64GB-4-0-Unlocked-Smartphone-/253482447437?var=552665991559"\],"paymentMethod":\["PayPal"\],"autoPay":\["false"\],"postalCode":\["10002"\],"location":\["New York,NY,USA"\],"country":\["US"\],"shippingInfo":\[{"shippingServiceCost":\[{"#currencyId":"USD","__value__":"0.0"}\],"shippingType":\["Free"\],"shipToLocations":\["Worldwide"\],"expeditedShipping":\["false"\],"oneDayShippingAvailable":\["false"\],"handlingTime":\["3"\]}\],"sellingStatus":\[{"currentPrice":\[{"#currencyId":"USD","__value__":"260.99"}\],"convertedCurrentPrice":\[{"#currencyId":"USD","__value__":"260.99"}\],"sellingState":\["Active"\],"timeLeft":\["P1DT14H31M1S"\]}\],"listingInfo":\[{"bestOfferEnabled":\["false"\],"buyItNowAvailable":\["false"\],"startTime":\["2018-03-11T10:01:51.000Z"\],"endTime":\["2018-08-08T10:01:51.000Z"\],"listingType":\["StoreInventory"\],"gift":\["false"\],"watchCount":\["104"\]}\],"returnsAccepted":\["true"\],"condition":\[{"conditionId":\["1000"\],"conditionDisplayName":\["New"\]}\],"isMultiVariationListing":\["true"\],"topRatedListing":\["false"\]},{"itemId":\["401421457135"\],"title":\["Apple iPhone 7 \"Factory Unlocked\" 32GB 4G LTE iOS WiFi Smartphone"\],"globalId":\["EBAY-US"\],"subtitle":\["USA Seller - No Contract Required - Fast Shipping!!"\],"primaryCategory":\[{"categoryId":\["9355"\],"categoryName":\["Cell Phones & Smartphones"\]}\],"galleryURL":\["http://thumbs1.ebaystatic.com/pict/04040_0.jpg"\],"viewItemURL":\["http://www.ebay.com/itm/Apple-iPhone-7-Factory-Unlocked-32GB-4G-LTE-iOS-WiFi-Smartphone-/401421457135?var=0"\],"paymentMethod":\["PayPal"\],"autoPay":\["true"\],"postalCode":\["07014"\],"location":\["Clifton,NJ,USA"\],"country":\["US"\],"shippingInfo":\[{"shippingServiceCost":\[{"#currencyId":"USD","__value__":"0.0"}\],"shippingType":\["Free"\],"shipToLocations":\["Worldwide"\],"expeditedShipping":\["true"\],"oneDayShippingAvailable":\["false"\],"handlingTime":\["1"\]}\],"sellingStatus":\[{"currentPrice":\[{"#currencyId":"USD","__value__":"319.95"}\],"convertedCurrentPrice":\[{"#currencyId":"USD","__value__":"319.95"}\],"sellingState":\["Active"\],"timeLeft":\["P29DT23H2M23S"\]}\],"listingInfo":\[{"bestOfferEnabled":\["false"\],"buyItNowAvailable":\["false"\],"startTime":\["2017-10-10T18:33:13.000Z"\],"endTime":\["2018-09-05T18:33:13.000Z"\],"listingType":\["StoreInventory"\],"gift":\["false"\],"watchCount":\["9152"\]}\],"returnsAccepted":\["true"\],"condition":\[{"conditionId":\["2500"\],"conditionDisplayName":\["Seller refurbished"\]}\],"isMultiVariationListing":\["true"\],"topRatedListing":\["true"\]}\]}\],"paginationOutput":\[{"pageNumber":\["1"\],"entriesPerPage":\["6"\],"totalPages":\["2779640"\],"totalEntries":\["16677839"\]}\],"itemSearchURL":\["http://www.ebay.com/sch/i.html?_nkw=iPhone&_ddo=1&_ipg=6&_pgn=1"\]}\]}][1]
Automation Anywhere does not come with a default JSON parsing tool. However, it does come with a DLL library you can use to translate JSON to XML, and AA works with XML documents just fine.
The library in question is Newtonsoft.Json.dll (you can find it in AA Client installation directory) and that has several useful methods for handling JSON (see here)

How to read body of HttpRequest POSTed to a REST web service - IBM Integration Bus

I am exposing a Rest based POST API and have to read few parameters in the body along with header. I am able to fetch the query string (header) parameters using HTTP Input node query string parser. As i have configured Input parser to JSON, it can not parse the incoming message and gives a runtime exception :
JSON parsing errors have occurred
Content-Type is set to :
application/x-www-form-urlencoded
I am very newbie with Rest/ JSON services on IIB. Help would be greatly appreciated.

Does OData4j request a response in JSON format or convert the response to JSON format? (Android)

I've been using the following code to create my android OData service consumer.
Services = ODataConsumer
.newBuilder("http://xxx.xxx.xxx.xxx:xxxxx/WCFDataServices.svc/")
.setFormatType(FormatType.JSON).build();
What I want to know is when the client makes a request through the Services consumer will the request make the server create a JSON formatted response or will the OData4j/consumer convert the response to JSON format.
Thanks in advance for the help. :)
It requests a JSON response from the server using the Accept request header. It does no conversion.
See: http://code.google.com/p/odata4j/source/browse/odata4j-jersey/src/main/java/org/odata4j/jersey/consumer/ODataJerseyClient.java#175
Hope that helps,
- john
Odata defalut format is ATOM. If you want you can change it to JSON, as you already doing.
"FormatType.JSON"
OData4j/consumer APIs are responsible to convert the response type whatever format you have defined.