Search parameter not working with the API request - json

I am new to json and APIs.
This particular dataset I am working with (https://api.cdnjs.com/libraries) is searchable by placing ?search=search_term after it (like: https://api.cdnjs.com/libraries?search=cloud). But when I use another json dataset (http://api.nobelprize.org/v1/prize.json for instance) it gives an error:
{ "error":"Using an unknown parameter" }
Does this have to do with how the datasets are set up? Methods perhaps? How do I make the other json searchable like the initial one (so I can use it in my search app)?

Navigating to the main domain of the provided url, you will find that the doc reside at https://nobelprize.readme.io/v1.0
To refine your results, as the docs suggest you should use the following parameters (when searching for prizes): year, yearTo, category and numberOfLaureates.
Here is an example of a refined search:
Request url: http://api.nobelprize.org/v1/prize.json?category=physics&year=2017
Response:
{
"prizes": [{
"year": "2017",
"category": "physics",
"laureates": [{
"id": "941",
"firstname": "Rainer",
"surname": "Weiss",
"motivation": "\"for decisive contributions to the LIGO detector and the observation of gravitational waves\"",
"share": "2"
}, {
"id": "942",
"firstname": "Barry C.",
"surname": "Barish",
"motivation": "\"for decisive contributions to the LIGO detector and the observation of gravitational waves\"",
"share": "4"
}, {
"id": "943",
"firstname": "Kip S.",
"surname": "Thorne",
"motivation": "\"for decisive contributions to the LIGO detector and the observation of gravitational waves\"",
"share": "4"
}]
}]
}
If it wasn't clear enough, I made a request to the API to retrieve data concerning prizes awarded in the physics category in the year 2017.

Related

Cloudwatch Logs Insights aggregating data for application dashboard

I have a lambda function that makes a call to a ticketing API, and returns a list of tickets and their attributes (open/resolved, assignee, etc). I want to build a dashboard within CloudWatch to show this information but I'm not sure if I'm approaching the problem correctly.
For example if I wanted a visualization of "Open tickets which are assigned to Jason" which changes over time. I've tried using Log Insights, but the response message is an array of tickets, which I've not been able to successfully query. The logs are structured as:
{
"level": "INFO",
"location": "get_all_tickets:18",
"message": [
{
"ticketId": "001",
"status": "Open",
"assignee": "Jason",
"requester": "Paul",
"createdAt": "2022-10-20 11:08:35.105000+00:00",
"lastUpdatedAt": "2022-10-25 13:42:52.881000+00:00",
"title": "Example Ticket 1",
},
{
"ticketId": "002",
"status": "Resolved",
"assignee": "Jason",
"requester": "John",
"createdAt": "2022-10-20 11:09:35.105000+00:00",
"lastUpdatedAt": "2022-10-25 13:42:52.881000+00:00",
"title": "Example Ticket 2",
}
],
"timestamp": "2022-10-27 18:26:32,680+0000",
"service": "ticket_metrics"
}
Within Logs Insights the fields are serialized as message.0.status, message.1.status, etc, but I haven't found a way to query and aggregate these. Is there a way I can produce a metric, like the above example "Open Tickets assigned to Jason" from within Logs Insights?
I tried queries from the Logs Insights docs, but these didn't perform as expected or didn't apply to my use case.

Parsing a very complex json response in dart

I'm trying to load a json file from a server response and parsing it in flutter, the model i create is working for all the other fields but i'm in trouble with this class
this is a part of the JSON response:
"episodes": {
"1": [
{
"id": "63",
"episode_num": 1,
"title": "Some Name",
"container_extension": "mp4",
"info": {
"director": "",
"plot": "",
"cast": "",
"rating": "",
"releasedate": "",
"movie_image": "",
"genre": "",
"duration_secs": 6495,
"duration": "01:48:15"
}
}
]
}
in this case the entry under episodes is just one but this will represents a season and all the episode inside it, so under episodes many of this entry (undefined number during coding) can be present
At this time, using online json to dart converter tools i can be able to retrive just this one entry but if a response have more than 1 season i can't see it.
There is any way to handle this?
EDIT:
Solved using a for cicle with max value = (json['episodes'].length + 1).
For the info stored inside each 'episodes' value i can use
json['episodes']['$i']
Valid JSON is always convertible to a Dart data structure. But what you may be asking is "can I get nested objects from this?", and that just depends on how hard you want to work. Some JSON-to-Dart tools are better than others and some JSON values are impossible for any automated tool to make sense of. Only real answer is: "it depends".

Microsoft Academic API, Knowledge graph search -- retrieved paper empty

I'm using the graph search method of the Microsoft Academic API to retrieve papers by ID using the following query:
{
"path": "/paper",
"paper": {
"type": "Paper",
"id": [2557283755],
"select": [
"PublishYear",
"CitationCount",
"OriginalTitle",
"NormalizedTitle",
"DOI"
]
}
}
The issue I'm having is that for some papers the response is completely empty, even though when I lookup the paper through the user interface, it has full metadata. For example, trying to retrieve this paper through the API yields
{
"Results": [
[
{
"CellID": 2557283755,
"PublishYear": "",
"CitationCount": "",
"OriginalTitle": "",
"NormalizedTitle": "",
"DOI": ""
}
]
]
}
while for a different paper the response is correct:
{
"Results": [
[
{
"CellID": 2112796928,
"PublishYear": "1998",
"CitationCount": "135",
"OriginalTitle": "Gradient-based learning applied to document recognition",
"NormalizedTitle": "gradient based learning applied to document recognition",
"DOI": "10.1109/5.726791"
}
]
]
}
Does anyone have any experience with this? To me it looks like an error in the database, but I wanted to make sure it's not something related to my query. Thanks!
The issue is caused by data version difference. The version of the academic graph data set used by graph search method might not be the same as that of Microsoft Academic portal https://academic.microsoft.com. We are deploying a new data pipeline to make the version difference as small as possible.

Access deeper elements of a JSON using postgresql 9.4

I want to be able to access deeper elements stored in a json in the field json, stored in a postgresql database. For example, I would like to be able to access the elements that traverse the path states->events->time from the json provided below. Here is the postgreSQL query I'm using:
SELECT
data#>> '{userId}' as user,
data#>> '{region}' as region,
data#>>'{priorTimeSpentInApp}' as priotTimeSpentInApp,
data#>>'{userAttributes, "Total Friends"}' as totalFriends
from game_json
WHERE game_name LIKE 'myNewGame'
LIMIT 1000
and here is an example record from the json field
{
"region": "oh",
"deviceModel": "inHouseDevice",
"states": [
{
"events": [
{
"time": 1430247045.176,
"name": "Session Start",
"value": 0,
"parameters": {
"Balance": "40"
},
"info": ""
},
{
"time": 1430247293.501,
"name": "Mission1",
"value": 1,
"parameters": {
"Result": "Win ",
"Replay": "no",
"Attempt Number": "1"
},
"info": ""
}
]
}
],
"priorTimeSpentInApp": 28989.41467999999,
"country": "CA",
"city": "vancouver",
"isDeveloper": true,
"time": 1430247044.414,
"duration": 411.53,
"timezone": "America/Cleveland",
"priorSessions": 47,
"experiments": [],
"systemVersion": "3.8.1",
"appVersion": "14312",
"userId": "ef617d7ad4c6982e2cb7f6902801eb8a",
"isSession": true,
"firstRun": 1429572011.15,
"priorEvents": 69,
"userAttributes": {
"Total Friends": "0",
"Device Type": "Tablet",
"Social Connection": "None",
"Item Slots Owned": "12",
"Total Levels Played": "0",
"Retention Cohort": "Day 0",
"Player Progression": "0",
"Characters Owned": "1"
},
"deviceId": "ef617d7ad4c6982e2cb7f6902801eb8a"
}
That SQL query works, except that it doesn't give me any return values for totalFriends (e.g. data#>>'{userAttributes, "Total Friends"}' as totalFriends). I assume that part of the problem is that events falls within a square bracket (I don't know what that indicates in the json format) as opposed to a curly brace, but I'm also unable to extract values from the userAttributes key.
I would appreciate it if anyone could help me.
I'm sorry if this question has been asked elsewhere. I'm so new to postgresql and even json that I'm having trouble coming up with the proper terminology to find the answers to this (and related) questions.
You should definitely familiarize yourself with the basics of json
and json functions and operators in Postgres.
In the second source pay attention to the operators -> and ->>.
General rule: use -> to get a json object, ->> to get a json value as text.
Using these operators you can rewrite your query in the way which returns correct value of 'Total Friends':
select
data->>'userId' as user,
data->>'region' as region,
data->>'priorTimeSpentInApp' as priotTimeSpentInApp,
data->'userAttributes'->>'Total Friends' as totalFriends
from game_json
where game_name like 'myNewGame';
Json objects in square brackets are elements of a json array.
Json arrays may have many elements.
The elements are accessed by an index.
Json arrays are indexed from 0 (the first element of an array has an index 0).
Example:
select
data->'states'->0->'events'->1->>'name'
from game_json
where game_name like 'myNewGame';
-- returns "Mission1"
select
data->'states'->0->'events'->1->>'name'
from game_json
where game_name like 'myNewGame';
This did help me

Freebase MQL to list out all commons types for a given word?

I'm trying to figure out how to write a MQL query to get a list of all the types associated to a given word.
For example I tried:
{
"id":null,
"name":null,
"name~=": "SOME_WORD",
"type":"/type/type",
"domain": {
"id": null,
"/freebase/domain_profile/category": {
"id": "/category/commons"
}
}
}​
I found this to list out all the Commons types or categories but haven't yet figured out how to narrow it down for a given input.
[{
"id": null,
"name": null,
"type": "/freebase/domain_profile",
"category": {
"id": "/category/commons"
}
}]​
There are a couple of different ways to do this with different tradeoffs for each.
Use the Search API with a query like this
https://www.googleapis.com/freebase/v1/search?indent=true&filter=%28all%20name{full}:%22uss%20constitution%22%29
You'll get back JSON results which look like this:
{
"status": "200 OK",
"result": [
{
"mid": "/m/07y14",
"name": "USS Constitution",
"notable": {
"name": "Ship",
"id": "/boats/ship"
},
"lang": "en",
"score": 1401.410400
},
...
You can make the matching more liberal by switching the "{full}" to "{phrase}" which will give you a substring match instead of an exact match.
Caveats:
- You'll only get a single "notable type" and it's fixed by Freebase's (unknown) algorithm
- I don't think there's a way to get both USS Constitution & U.S.S. Constitution results
- You can get a list of all types by adding &mql_output={"type":[]}, but then you lose the "notable" type. I don't think there's a way to get both in a single call.
Use MQL
This query returns the basic information that you want:
[{
"name~=":"uss constitution",
"type":[],
"/common/topic/notable_types" : []
}]​
Caveats:
It won't find "uss constitution" which is an alias rather than the primary name (there's a recipe in the MQL cookbook for that though)
It won't find "u.s.s. constitution"
The "notable_types" API is an MQL extension and MQL extensions aren't supported in the new Freebase API, only the legacy deprecated API
You're tied to whatever (unknown) algorithm Freebase used to compute "notability"
Depending on what you are trying to accomplish, you might need something more sophisticated than this (as well as a deeper understanding of what's in Freebase), but this should get you going with the basics.
Did you try:
[{
"name": "David Bowie",
"type": []
}]