I am using nodejs and below are the data returned from Google Book API. I wanted to access the information "Authors" from the data which is under a square bracket, however I am not able to access it. I tried a couple of methods but still fail to access them.
{
"kind": "books#volumes",
"totalItems": 42,
"items": [
{
"kind": "books#volume",
"id": "TpuJxgEACAAJ",
"etag": "kFhVXIpo2Aw",
"selfLink": "https://www.googleapis.com/books/v1/volumes/TpuJxgEACAAJ",
"volumeInfo": {
"title": "The Guardians",
"authors": [
"John Grisham"
],
"publisher": "Random House Large Print",
"publishedDate": "2019-10-15",
"description": "The suspense never rests in John Grisham's pulse-pounding new legal thriller. The latest novel from the New York Times #1 bestselling author moves at breakneck speed, delivering some of his most inventive twists and turns yet. In the small north Florida town of Seabrook, a young lawyer named Keith Russo was shot dead at his desk as he worked late one night. The killer left no clues behind. There were no witnesses, no real suspects, no one with a motive. The police soon settled on Quincy Miller, a young black man who was once a client of Russo's. Quincy was framed, convicted, and sent to prison for life. For twenty-two years he languished in prison with no lawyer, no advocate on the outside. Then he wrote a letter to Guardian Ministries, a small innocence group founded by a lawyer/minister named Cullen Post. Guardian handles only a few innocence cases at a time, and Post is its only investigator. He travels the South fighting wrongful convictions and taking cases no one else will touch. With Quincy Miller, though, he gets far more than he bargained for. Powerful, ruthless people murdered Keith Russo, and they do not want Quincy exonerated. They killed one lawyer twenty-two years ago, and they will kill another one without a second thought.",
"industryIdentifiers": [
{
"type": "ISBN_10",
"identifier": "0525639381"
},
{
"type": "ISBN_13",
"identifier": "9780525639381"
}
],
"readingModes": {
"text": false,
"image": false
},
"pageCount": 480,
"printType": "BOOK",
"categories": [
"Fiction"
],
"maturityRating": "NOT_MATURE",
"allowAnonLogging": false,
"contentVersion": "preview-1.0.0",
"panelizationSummary": {
"containsEpubBubbles": false,
"containsImageBubbles": false
},
"imageLinks": {
"smallThumbnail": "http://books.google.com/books/content?id=TpuJxgEACAAJ&printsec=frontcover&img=1&zoom=5&source=gbs_api",
"thumbnail": "http://books.google.com/books/content?id=TpuJxgEACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api"
},
"language": "en",
"previewLink": "http://books.google.com.my/books?id=TpuJxgEACAAJ&dq=the+guardian+inauthor:john+grisham&hl=&cd=1&source=gbs_api",
"infoLink": "http://books.google.com.my/books?id=TpuJxgEACAAJ&dq=the+guardian+inauthor:john+grisham&hl=&source=gbs_api",
"canonicalVolumeLink": "https://books.google.com/books/about/The_Guardians.html?hl=&id=TpuJxgEACAAJ"
},
"saleInfo": {
"country": "MY",
"saleability": "NOT_FOR_SALE",
"isEbook": false
},
"accessInfo": {
"country": "MY",
"viewability": "NO_PAGES",
"embeddable": false,
"publicDomain": false,
"textToSpeechPermission": "ALLOWED",
"epub": {
"isAvailable": false
},
"pdf": {
"isAvailable": false
},
"webReaderLink": "http://play.google.com/books/reader?id=TpuJxgEACAAJ&hl=&printsec=frontcover&source=gbs_api",
"accessViewStatus": "NONE",
"quoteSharingAllowed": false
},
"searchInfo": {
"textSnippet": "In the small north Florida town of Seabrook, a young lawyer named Keith Russo was shot dead at his desk as he worked late one night."
}
}
]
}
Below is how I try to access:
const volumeInfo.authors = body.items[0].volumeInfo.authors;
The nodejs will crash under body.items[0] when I run it. I also try to get the keys underneath "items" but it will flag errors.
Have you tried parsing the response into JSON using JSON.parse method?
Related
Here is the code
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
await lib.discord.channels['#0.3.2'].messages.create({
"channel_id": ${context.params.event.channel_id},
"content": "",
"tts": false,
"embeds": [
{
"type": "rich",
"title": Staff Guidebook!,
"description": Here you can find the **punishment guide** and the **commands lists** to assist you!,
"color": 0xff0000,
"fields": [
{
"name": Dyno Commands List,
"value": https://dyno.gg/commands,
"inline": true
},
{
"name": Staff Punishment Guide,
"value": https://docs.google.com/spreadsheets/d/15JoaAvjOqaFDATEG91lS1UPOY-8gMIO112-kif2oiB8/edit?usp=sharing,
"inline": true
},
{
"name": Staffing Rules,
"value": - Staff cannot moderate other staff, you must create a support ticket instead.\n- You mut be as helpful as possible at all times.\n- You do not have to be proffesional at all times however when dealing with a staff \nsituation (aka. tickets) you must remain proffesional and use grammer at all times.\n- Being staff does not stop you from being within our rules. Any staff who break rules \nwill be punished accordingly by our support team.\n- You cannot leak any punishments or staff only information to other people, this can result in your removal from the staff team.\n- Keep calm when dealing with situations.\n- Always have evidence ready if you are going to punish someone.,
"inline": true
}
]
}
]
});
When I put it in, it comes out like a normal text message.
I am using coinbase pro api using sandbox and testing a sell case.
The order i am placing is
const sellParams:any = {
'side': 'sell',
'product_id': 'BTC-USD',
'type': 'market',
'size': '0.009'
}
the response in order status comes as below
{
"type": "market",
"id": "5846345c-c070-44bf-9d31-ec07a1c9892c",
"product_id": "BTC-USD",
"side": "sell",
"post_only": false,
"created_at": "2019-08-12T04:08:29.845922Z",
"fill_fees": "0.0297509100000000",
"filled_size": "0.00300000",
"executed_value": "9.9169700000000000",
"status": "done",
"settled": true,
"done_at": "2019-08-12T04:08:29.853Z",
"done_reason": "canceled",
"size": "0.00900000"
}
the question is on executed value which shows 9.9169... should not it be around 100 USD ?
so basically sandbox prices are different than the actual prices and thats where the confusion was.
The ActivityStreams specification explains the difference between to, cc, bto, and bcc in section 5.1. But there's also an audience property, defined as:
one or more entities that represent the total population of entities for which the object can considered to be relevant.
How is this different from "to" and "cc"? In particular, what's the different effect on ActivityPub delivery?
The answer can be found in the Issue list of the ActivityPub spec, in this comment by James M Snell:
audience is used for targeting.
For example, suppose I have an activity that everyone in my company should see show up in their activity feeds, but only certain specific people should be notified, I would end up with something like:
{
//...//
"audience": {
"type": "Organization",
"id": "http://example.org",
"name": "My Organization"
},
"to": ["http://jane.example.org", "http://joe.example.org"],
"cc": ["http://sally.example.org"]
}
Here, the audience property provides a scoping of the overall audience, while the to and cc fields identify specific individuals within that audience that should be notified more directly of the activity.
After this discussion the specification was updated. See Audience targeting and specifically in par. 5.1.1 there is some more clarification on its use:
Activities are rarely isolated events. Often, multiple individual activities will be performed around a similar context or audience. For instance, a collaborators working on a shared project might perform multiple related activities in the process of achieving some goal. Such activities can be logically grouped together using the context property, and scoped to a particular audience using the audience property.
With the following example supplied (Example 144):
{
"#context": "https://www.w3.org/ns/activitystreams",
"summary": "Activities in Project XYZ",
"type": "Collection",
"items": [
{
"summary": "Sally created a note",
"type": "Create",
"id": "http://activities.example.com/1",
"actor": "http://sally.example.org",
"object": {
"summary": "A note",
"type": "Note",
"id": "http://notes.example.com/1",
"content": "A note"
},
"context": {
"type": "http://example.org/Project",
"name": "Project XYZ"
},
"audience": {
"type": "Group",
"name": "Project XYZ Working Group"
},
"to": "http://john.example.org"
},
{
"summary": "John liked Sally's note",
"type": "Like",
"id": "http://activities.example.com/1",
"actor": "http://john.example.org",
"object": "http://notes.example.com/1",
"context": {
"type": "http://example.org/Project",
"name": "Project XYZ"
},
"audience": {
"type": "Group",
"name": "Project XYZ Working Group"
},
"to": "http://sally.example.org"
}
]
}
I got the error code Error code: InvalidIntentSamplePhraseSlot when I built the model using the new skills console.
The full error message is
Sample utterance "AddBookmarkIntent i am at {pageno} of {mybook}" in intent "AddBookmarkIntent" cannot include both a phrase slot and another intent slot. Error code: InvalidIntentSamplePhraseSlot -
where {pageno} is AMAZON.NUMBER and {mybook} is AMAZON.SearchQuery
What is the error about and how can I solve it?
edit: add the JSON for the intent
{
"name": "AddBookmarkIntent",
"slots": [
{
"name": "mybook",
"type": "AMAZON.SearchQuery"
},
{
"name": "pageno",
"type": "AMAZON.NUMBER"
}
],
"samples": [
"i am at {pageno} of the book {mybook}",
"save page {pageno} to the book {mybook}",
"save page {pageno} to {mybook}",
"i am at {pageno} of {mybook}"
]
}
It's not allowed to have a slot of the type AMAZON.SearchQuery in the same Utterance with another slot, in your case AMAZON.NUMBER.
Mark one of the slots as required and ask for them separately.
A little example:
Create the Intent put in the utterances and slots:
"intents": [
{
"name": "AddBookmarkIntent",
"samples": [
"I am at {pageno}"
],
"slots": [
{
"name": "mybook",
"type": "AMAZON.SearchQuery",
"samples": [
"For {mybook}"
]
},
{
"name": "pageno",
"type": "AMAZON.NUMBER"
}
]
}
Mark the specific slot as required so Alexa will automatically ask for it:
"dialog": {
"intents": [
{
"name": "AddBookmarkIntent",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "mybook",
"type": "AMAZON.SearchQuery",
"elicitationRequired": true,
"confirmationRequired": false,
"prompts": {
"elicitation": "Elicit.Intent-AddBookmarkIntent.IntentSlot-mybook"
}
}
]
}
]
}
and create the prompts to ask for the slot:
"prompts": [
{
"id": "Elicit.Intent-AddBookmarkIntent.IntentSlot-mybook",
"variations": [
{
"type": "PlainText",
"value": "For which book you like to save the page?"
}
]
}
]
This is probably much easier with the skill builder BETA and not its editor because it will automatically create the JSON in the background.
The error is telling you that you have an Intent name in your Sample Utterance where it should only have Slots and it looks like you do.
"AddBookmarkIntent i am at {pageno} of {mybook}"
"AddBookmarkIntent" shouldn't actually be inside of the utterance. So turn your utterance into:
"i am at {pageno} of {mybook}"
I know that some of the documents show an example of the sample utterances with the Intent Name first, such as here. But that has a big warning near the top:
So you have to be careful about which documents you read and follow based on which way you are building your Alexa Skill.
Follow this if you are using the Skill Builder.
It unfortunately seems like an utterance can only reference 1 "Phrase" slot type.
For your specific case, it does look like there is now a non-phrase slot type AMAZON.Book in public beta; if you use that instead of AMAZON.SearchQuery it might work?
Src: https://developer.amazon.com/en-US/docs/alexa/custom-skills/slot-type-reference.html
I'm doing a Http get in Angular 2 and the response is a JSON. However, i'm trying to use this in a ngFor but i can't because it isn't an Array.
How can I convert JSON to Array in Angular 2? I searched in many websites but didn't discover a effective way to do that.
Edit 1:
The response is like that:
{
"adult": false,
"backdrop_path": "/fCayJrkfRaCRCTh8GqN30f8oyQF.jpg",
"belongs_to_collection": null,
"budget": 63000000,
"genres": [
{
"id": 18,
"name": "Drama"
}
],
"homepage": "",
"id": 550,
"imdb_id": "tt0137523",
"original_language": "en",
"original_title": "Fight Club",
"overview": "A ticking-time-bomb insomniac and a slippery soap salesman channel primal male aggression into a shocking new form of therapy. Their concept catches on, with underground \"fight clubs\" forming in every town, until an eccentric gets in the way and ignites an out-of-control spiral toward oblivion.",
"popularity": 0.5,
"poster_path": null,
"production_companies": [
{
"name": "20th Century Fox",
"id": 25
}
],
"production_countries": [
{
"iso_3166_1": "US",
"name": "United States of America"
}
],
"release_date": "1999-10-12",
"revenue": 100853753,
"runtime": 139,
"spoken_languages": [
{
"iso_639_1": "en",
"name": "English"
}
],
"status": "Released",
"tagline": "How much can you know about yourself if you've never been in a fight?",
"title": "Fight Club",
"video": false,
"vote_average": 7.8,
"vote_count": 3439
}
I think if you want to pass from json to array you could do the following command:
var arr = []
for(i in json_object){
arr.push(i)
arr.push(json_object[i])
}
Then you have every keys in the even index and every contents in the odd index
Well, I really don't see the point here. Arrays are for operating with lists of similar objects or types, not for complex structures. If you had a bunch of objects similar to the one you show, then it would make sense. Anyways, if you really want an array then you could do it with recursion and create a flat array of the properties.
var flatPropertyArray = [];
function flatten(obj) {
for (var property in obj) {
if (obj.hasOwnProperty(property)) {
if (typeof obj[property] == "object")
flatten(obj[property]);
else
flatPropertyArray.push(property);
}
}
}
pass your JSON into the flatten func.