Best way to read contents from a .json link - json

I've been given a link to a .json file, what is the best way to go about retrieving the contents and then parsing it?

If you are trying to do this in Titanium mobile then...
Fetch the JSON data using Titanium.Network.HTTPClient
Then transform the response to JSON object using JSON.parse()
Hope that helps

In JavaScript you can use this: JSON in JavaScript
and in PHP exists built-in functions for that: JSON in PHP
And when you are using JavaScript you can fetch the data with a simple Ajax request.

Related

Extract fields from JSON API response made with Blueprism

I am using Blueprism to make an API Call. The response is a block of json. I need to extract the conversationId from:
{"results":[{"group":{"queueId":"aad701ad-56db-452e-8b70-aa9abd6046c7","mediaType":"email"},"data":[{"metric":"oWaiting","stats":{"count":1},"truncated":false,"observations":[{"observationDate":"2022-01-20T11:19:04.882Z","conversationId":"116b9f91-bf82-4275-9cdc-c405068b4cba","sessionId":"f97de11e-eb99-4781-ae13-33a9e5b6c3f0","routingPriority":0,"direction":"inbound","addressFrom":"e.mc#gmail.ie","addressTo":"info#gmail.ie","requestedRoutings":["Standard"]}]}]}]}
I am using this regex:
^.*? with conversationId ([a-f0-9]+)
but it is not working. Is this the best approach? Is there a better way to do this?
.*conversationId":"([^"]+)".*
will save the conversationId into capture group 1.
If you are using perl, you could do this:
s/.*conversationId":"([^"]+)".*/\1/
this works for your example but it's probably not going to scale well to different input JSON messages. As others have mentioned, the right way to do this is to parse the string into a native JSON object and then extract the field using it's methods.
Ultimately I was going about this the wrong way. I should have been parsing the json and not trying to extract a particular string.
Blueprism has a json object which completes this very function.
https://digitalexchange.blueprism.com/dx/entry/3439/solution/utility---json

Django rest swagger and json definition

I'm pretty new to Django and I'm currently working on a project where Django-rest-framework is used and the documentation is created with Swagger trough the django-rest-swagger package.
I'm trying to find (or generate) a swagger.json definition file, any idea on where it can be found with this package? I would like to use it to generate client side code.
Thanks
The swagger schema definition can be generated with https://github.com/signalfx/fetch-swagger-schema regardless the api implementation.
You can append ?format=openapi to the end of your docs URL and it will return the raw JSON text instead of the UI.
see here

how to convert XML to JSON in angularjs?

I want to load an xml file and convert it into JSON in angularjs on the client side.
You have two options.
Return the data from the API in format you require to prevent conversions (recommended).
Convert the XML to JSON using javascript.
For approach #2 I'll recommend you this solution http://goessner.net/download/prj/jsonxml/
And please be sure to read the article 'Converting Between XML and JSON' (by Stefan Goessner) to overview details of the problems with conversions.

Displaying JSON as nested table in Node.js

I have a JSON object and I want to display it in the form of a table in Node.js. The table should have nested rows depending on the existence of nested records in the JSON object. I considered jstree plugin but it will be difficult to convert JSON to the JSON array needed by it. Can anyone please suggest me a better option? Any plugin or snippet that could give me a direction?
There is a third party plugin to jstree called jstree-grid:
https://github.com/deitch/jstree-grid
As for converting the JSON - you can use core.data as a function and convert the format on the client side.
Try this jsonastable
Ot is a clone of json2table but MIT licensed.
You can include it in your site.

Retrieving a JSON object from a server with JSP

I am new to JSP and I am having trouble finding a simple concrete example to make a request to a server that returns a JSON object.
What I am trying to do is something like:
myjson_object = getJSONfrom("my.webserver.com/get/json")
I basically want to add such a line to an existing JSP page so that I can have the JSON object available. I would like to avoid using AJAX or JQuery. I have found several examples like this one, but for some reason they do not work in my case.
Probably trying to do that operation into JSP is not a good idea, since you'd need to use scriptlets and I understand scriptlets are now considered not a good practice (see this)... You'd better do it into a servlet (see this)...
Anyway the code would be similar. You first need to make the request and then parse the JSON response...
In order to make the request you can use HttpURLConnection class. See this question.
Once you have the server response into a BufferedReader, you can parse the JSON using some library, such as Gson. You can find lots of examples of JSON deserializing using Gson in SO, like this or this.