How can I fetch the json into web api and get the specific data?
For example, this is my web api "https://api.coinmarketcap.com/v2/ticker/1/" and the output is like this:
{
"data": {
"id": 1,
"name": "Bitcoin",
"symbol": "BTC",
"website_slug": "bitcoin",
"rank": 1,
"circulating_supply": 17145625.0,
"total_supply": 17145625.0,
"max_supply": 21000000.0,
"quotes": {
"USD": {
"price": 6196.07,
"volume_24h": 3623440000.0,
"market_cap": 106235492694.0,
"percent_change_1h": -0.08,
"percent_change_24h": -2.9,
"percent_change_7d": -6.64
}
},
"last_updated": 1531423345
},
"metadata": {
"timestamp": 1531423031,
"error": null
}
}
I want a code how I can open the "web api link", "get the json into web api", "get the data in json".
I'm not really sure what language you are using. It would be helpful to provide that information in the tags or the question itself
If you are using python 3.7
import json
from urllib.request import urlopen
myjson = JSON.loads(urlopen("https://api.coinmarketcap.com/v2/ticker/1/"))
Here you will get the json deserialized into native python nested arrays and dictionaries (dictionaries in your case).
From this you can access elements from the json just like you would any element from a normal python dictionary. For example if I wanted to access the id
myjson["data"]["id"]
Hope this helped! Best of luck... please reply what language you are using and any frameworks so the community can help you in the best way.
Related
Am reading this "issue" from the guys from adaptive cards, and am trying to use their parsing way in my own project with no results. HereĀ“s the entire thing https://github.com/microsoft/AdaptiveCards/issues/2448 the parsing section is below. Does this implementation really work?
JSON.parse Example
This is an Azure DevOps response where the message property is a JSON-serialized string. In order to access values within the string, we need to use the JSON.parse function in our template.
Data
{
"id": "1291525457129548",
"status": 4,
"author": "Matt Hidinger",
"message": "{\"type\":\"Deployment\",\"buildId\":\"9542982\",\"releaseId\":\"129\",\"buildNumber\":\"20180504.3\",\"releaseName\":\"Release-104\",\"repoProvider\":\"GitHub\"}",
"start_time": "2018-05-04T18:05:33.3087147Z",
"end_time": "2018-05-04T18:05:33.3087147Z"
}
Usage
{
"type": "TextBlock",
"text": "{JSON.parse(message).releaseName}"
}
Resulting In
{
"type": "TextBlock",
"text": "Release-104"
}
just like the question asked here
I do a query or scan operation on dynamoDB using dynamoDB proxy service on AWS API Gateway to read data for the Client and I get DynamoDB formatted JSON data in reply.
Although I can use the "Method Response" to convert but when the Data is above 1000 records - I cannot handle it due to the limitation of foreach loop in Method Response.
Is there a flag or a setting somewhere in dynamodb or in api gateway such that I get normal json rather than the dynamoDB formatted JSON ?
DynamoDB Formatted JSON example
{
"videos": [
{
"file": {
"S": "file1.mp4"
},
"id": {
"S": "1"
},
"canvas": {
"S": "This is Canvas1"
}
},
{
"file": {
"S": "main.mp4"
},
"id": {
"S": "0"
},
"canvas": {
"S": "this is a canvas"
}
}
]
}
Normal Json example of the same
{
"videos": [
{
"file": "file1.mp4",
"id": "1",
"canvas": "This is Canvas1"
},
{
"file": main.mp4",
"id": "0",
"canvas": "this is a canvas"
}
]
}
Using an Integration Response mapper!
The mapper would probably look something like: (I'm using your provided response)
#set($inputRoot = $input.path('$'))
{
"videos": [
#foreach($elem in $inputRoot.Items)
{ "file": "$elem.file.S",
"id": "$elem.id.S",
"canvas": "$elem.canvas.S" }#if($foreach.hasNext), #end
#end
]
}
Please consult the linked documentation for more complete guidance on attaching AWS Services directly to API Gateway.
The possible solution for this is using a aws lambda to query/scan dynamoDb and reply back the domain object after converting it into a json using some json lib, like GSON or jackson.
If any one has knowledge about an alternate option - please do post here. Thanks
The following is a sample schema from the OneNote API documentation at this site and will can be used with json2csharp.com with no problems.
http://dev.onenote.com/docs#/reference/get-notebooks.
{
"createdBy": "user name",
"createdTime": "2013-10-05T10:57:00.683Z",
"id": "notebook ID",
"isDefault": false,
"isShared": false,
"lastModifiedBy": "user name",
"lastModifiedTime": "2014-01-28T18:49:00.47Z",
"links": {
"oneNoteClientUrl": {
"href": "onenote:https://{client URL}"
},
"oneNoteWebUrl": {
"href": "https://{web URL}"
}
},
"name": "notebook name",
"sectionGroupsUrl": "https://www.onenote.com/api/v1.0/notebooks/{notebook ID}/sectionGroups",
"sectionsUrl": "https://www.onenote.com/api/v1.0/notebooks/{notebook ID}/sections",
"self": "https://www.onenote.com/api/v1.0/notebooks/{notebook ID}",
"userRole": "Contributor"
}
However, using the following Get Notebooks link has a different schema that doe
sn't pass json2csharp. Parsing your JSON didn't work. Please make sure it's valid.
"https://graph.microsoft.com/v1.0/me/onenote/notebooks"
createdBy and lastmodifiedBy are thrown as exceptions.
The sample from the apigee.com/console app uses the https://www.onenote.com/api/v1.0/me/notes/notebooks link and has the correct schema.
How do I resolve this discrepancy? Or am I mistaken?
The response payload returned from the Microsoft Graph API is slightly different from the response payload returned from the OneNote API directly.
Here's a reference to the notebook properties returned from Microsoft Graph: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/notebook
And this is what gets returned from the OneNote API directly:
https://msdn.microsoft.com/en-us/library/office/dn769050.aspx => Response properties
Disclaimer: this is my first time attempting to write in Javascript; I don't know what I am doing.
I tried looking for example of this, but everything I found has the JSON object included in Javascript. Trying to return just the price_usd from this JSON
https://api.coinmarketcap.com/v1/ticker/bitcoin/
[
{
"id": "bitcoin",
"name": "Bitcoin",
"symbol": "BTC",
"rank": "1",
"price_usd": "972.935",
"price_btc": "1.0",
"24h_volume_usd": "501202000.0",
"market_cap_usd": "15650425175.0",
"available_supply": "16085787.0",
"total_supply": "16085787.0",
"percent_change_1h": "-2.35",
"percent_change_24h": "-17.36",
"percent_change_7d": "2.55",
"last_updated": "1483690766"
}
]
My current code in the linked function box is :
return {payload:msg.payload.price_usd};
msg.payload returns undefined. Tried with both http request set to return as parsed JSON object and as UTF-8 string.
The response is surrounded by [ ]. This indicates it's an array. So you need to reference into that array to get to the data.
msg.payload[0].price_usd
I'm aware of this question but I don't believe that there is no solution with standars component. I'm using Talend ESB Studio 5.4.
I have to parse a JSON string from a REST web service into multiple output, and add them to a database.
Database has two tables:
User (user_id, name, card, card_id, points)
Action (user_id, action_id, description, used_point)
My JSON Structure is something like that:
{
"users": [
{
"name": "foo",
"user_id": 1,
"card": {
"card_id": "AAA",
"points": 10
},
"actions": [
{
"action_id": 1,
"description": "buy",
"used_points": 2
},
{
"action_id": 3,
"description": "buy",
"used_points": 1
}
]
},
{
"name": "bar",
"user_id": 2,
"card": {
"card_id": "BBB",
"points": -1
},
"actions": [
{
"id": 2,
"description": "sell",
"used_point": 5
}
]
}
]
}
I have tried to add a JSON Schema Metadata but it is not clear to me how to "flat" the JSON. I have tried to look at tXMLMap, tExtractJSONFields.. but no luck till now.
I also had a look at tJavaRow but I don't understand how to make a Schema for that.
It's a pity because till now I'm loving Talend! Any advice?
You can save a json file in your disk, then create new json file in the metadata of Talend studio, the wizard retrieve the schema for you, after saving, you ca, copie schema in the generic schema of the metadata, and it's done, use that generic schema where you want, this is how to use generic schema in the tRestClient component: