The assemble.io documentation gives some examples of using simple JSON as a data source, such as:
{
"title": "Assemble" ,
"author": "Brian Woodward"
}
But, what if I wanted to use a more complex JSON structure for my data (to display a list of books on a single page)? How can that be done?
{
"books": [
{
"title": "Book A",
"author": "Fred"
},
{
"title": "Book 47",
"author": "Joe"
}
]
}
Let say your library.json contain:
{
"books": [
{
"title": "Book A",
"author": "Fred"
},
{
"title": "Book 47",
"author": "Joe"
}
]
}
Use {{each}} (Assemble use handlebarjs for default templating) to display a list of books on a single page:
{{#each library.books}}
{{title}} - {{author}}
{{/each}}
Related
Version 4 of the Amazon product advertising api let you use the AlternateVersions response group to get related products, which for books let you get all the different formats of a book listing (hardcover, paperback, mass market, etc.)
Version 5 of the API does not have AlternateVersions for some reason. Is there any way to get the different versions of a book in PAAPI5?
I'm having the same issue. In my case I need just hardcover and kindle version of a book.
GetVariations (successor of AlternateVersions) is for some reason not working for books and just returns no result back.
The only possible way that I'm aware of is to do two API request (SearchItems) including the specific search index Books for books and KindleStore for kindle files. Not specifying the search index normally returns you just the hardcopy of the Books search index.
To differentiate between books and kindle version check the ItemInfo.Classifications.ProductGroup.DisplayValue or ItemInfo.Classifications.Binding.DisplayValue
For some unknown reason (at least to me) the API is returning only a subset of results when not specifying the search index (in the below example the kindle one)
Example
In the following example I looking for the hardcopy or kindle of the book with ISBN 9780262043649 by doing a SearchItem request.
a) Hardcopy with given search index
Payload
{
"Keywords": "9780262043649",
"Resources": [
"ItemInfo.Classifications",
"ItemInfo.Title"
],
"SearchIndex": "Books",
"PartnerTag": "*******",
"PartnerType": "Associates",
"Marketplace": "www.amazon.com",
"Operation": "SearchItems"
}
Response
{
"SearchResult": {
"Items": [
{
"ASIN": "0262043645",
"DetailPageURL": "https://www.amazon.com/dp/0262043645?tag=getabstractcom&linkCode=osi&th=1&psc=1",
"ItemInfo": {
"Classifications": {
"Binding": {
"DisplayValue": "Hardcover",
"Label": "Binding",
"Locale": "en_US"
},
"ProductGroup": {
"DisplayValue": "Book",
"Label": "ProductGroup",
"Locale": "en_US"
}
},
"Title": {
"DisplayValue": "Novacene: The Coming Age of Hyperintelligence (The MIT Press)",
"Label": "Title",
"Locale": "en_US"
}
}
}
],
"SearchURL": "https://www.amazon.com/s?k=9780262043649&i=stripbooks&rh=p_n_availability%3A-1&tag=getabstractcom&linkCode=osi",
"TotalResultCount": 1
}
}
b) Kindle with given search index
Payload
{
"Keywords": "9780262043649",
"Resources": [
"ItemInfo.Classifications",
"ItemInfo.Title"
],
"SearchIndex": "KindleStore",
"PartnerTag": "******",
"PartnerType": "Associates",
"Marketplace": "www.amazon.com",
"Operation": "SearchItems"
}
Response
{
"SearchResult": {
"Items": [
{
"ASIN": "B08BT4MM18",
"DetailPageURL": "https://www.amazon.com/dp/B08BT4MM18?tag=getabstractcom&linkCode=osi&th=1&psc=1",
"ItemInfo": {
"Classifications": {
"Binding": {
"DisplayValue": "Kindle Edition",
"Label": "Binding",
"Locale": "en_US"
},
"ProductGroup": {
"DisplayValue": "Digital Ebook Purchas",
"Label": "ProductGroup",
"Locale": "en_US"
}
},
"Title": {
"DisplayValue": "Novacene: The Coming Age of Hyperintelligence",
"Label": "Title",
"Locale": "en_US"
}
}
}
],
"SearchURL": "https://www.amazon.com/s?k=9780262043649&i=digital-text&rh=p_n_availability%3A-1&tag=getabstractcom&linkCode=osi",
"TotalResultCount": 1
}
}
c) No specific search index
Payload
{
"Keywords": "9780262043649",
"Resources": [
"ItemInfo.Classifications",
"ItemInfo.Title"
],
"PartnerTag": "*******",
"PartnerType": "Associates",
"Marketplace": "www.amazon.com",
"Operation": "SearchItems"
}
Response
{
"SearchResult": {
"Items": [
{
"ASIN": "B08BT4MM18",
"DetailPageURL": "https://www.amazon.com/dp/B08BT4MM18?tag=getabstractcom&linkCode=osi&th=1&psc=1",
"ItemInfo": {
"Classifications": {
"Binding": {
"DisplayValue": "Kindle Edition",
"Label": "Binding",
"Locale": "en_US"
},
"ProductGroup": {
"DisplayValue": "Digital Ebook Purchas",
"Label": "ProductGroup",
"Locale": "en_US"
}
},
"Title": {
"DisplayValue": "Novacene: The Coming Age of Hyperintelligence",
"Label": "Title",
"Locale": "en_US"
}
}
}
],
"SearchURL": "https://www.amazon.com/s?k=9780262043649&rh=p_n_availability%3A-1&tag=getabstractcom&linkCode=osi",
"TotalResultCount": 1
}
}
You can try those examples in the API's scratchpad.
More information about the search index of the product advertising API is available on the official documentation here
I'm trying to conditionally extract the value of an element from the following sample json response:
{
"books": [
{
"title": "book 1 title",
"author": {
"firstName": "author01",
"lastName": "abc"
}
}
{
"title": "book 2 title",
"author": {
"firstName": "author02",
"lastName": "xyz"
}
}
]
}
I want to select the book title where lastName == xyz. Here the expression that I use:
$.books[?(#.author.lastName=='xyz')]
but it returns []
Thanks
Your JSON Path expression is correct, demo:
however there is a problem with your JSON:
{
"books": [
{
"title": "book 1 title",
"author": {
"firstName": "author01",
"lastName": "abc"
}
}, <-----------------------------you need the comma here
{
"title": "book 2 title",
"author": {
"firstName": "author02",
"lastName": "xyz"
}
}
]
}
If your response cannot be resolved to a valid JSON - you will have to use Regular Expression Extractor instead. If it is - double check your JSON Path expression and also worth checking out JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios
Try below expression:
$.books[?(#.author.lastName=='xyz')].title
I have following json file,
{
"catalog": {
"book": [
{
"id": "bk101",
"author": "Gambardella, Matthew",
"title": "XML Developer's Guide",
"genre": "Computer",
"price": "44.95",
"publish_date": "2000-10-01",
"description": "An in-depth look at creating applications with XML."
},
{
"-id": "bk102",
"author": "Ralls, Kim",
"title": "Midnight Rain",
"genre": "Fantasy",
"price": "5.95",
"publish_date": "2000-12-16",
"description": "A former architect battles "
}
]
}
}
I want to get only few elements from the above, for eg.
catalog.book[0].title should give result
{
"catalog": {
"book": [
{ "title": "XML Developer's Guide"}
]
}
}
But it will give result only {"title": "XML Developer's Guide"}, the tree is missing.
Please help.
you have to create a function which return the subset of json .subset contain all the field you want
//simple javascript code
function subset_of_json(jsonobj,fieldsYouWant){
//fieldsYouWant is an array ['title'] or ['title' ,'id'] or any field you want
var json ={catalog :{book:[]}};
var bookArr =jsonobj.catalog.book;
for(var i=0;i<bookArr.length;i++){
var obj ={};
for(var k=0;k<fieldsYouWant.length;k++){
obj[fieldsYouWant[k]]=bookArr[i][fieldsYouWant[k]];
}
json.catalog.book.push(obj)
}
return json
}
I want to use the RavenDB. I want to do a system for administration news with comments.
I expect perhaps 500 comments in one news.
What is correct structure for news with comments? Whats type of cases can I use the following structures of the documents?
1.) Comments are in the news object
{
"News": [
{
"NewsId": "1",
"Title": "Name",
"Content": "Text",
"Comments": [
{
"CommentId": "1",
"Comment": "Text"
},
{
"CommentId": "2",
"Comment": "Text"
}
]
}
]
}
2.) News and comments are into separate objects:
News:
{
"News": [
{
"NewsId": "1",
"Title": "Name",
"Content": "Text",
"CommentId": "1"
}
]
}
Comments:
{
"Comments": [
{
"CommentId": "1",
"Comment": "Text"
},
{
"CommentId": "2",
"Comment": "Text"
}
]
}
Usually you will want to put this on separate objects, if you are accessing the news item without the comments.
I am trying to parse the json result object and use html template in a widget to display.
The json looks like this
Result": [
{
"Website": "Testing ",
"Description": "Content from yahoo ",
"LinkGroup": {
"entry": [
{
"linkType": "information",
"Link": {
"title": "Test1",
"url": "http://yahoo.com",
"description": "my Link Description"
}
},
{
"linkType": "news link",
"Link": {
"title": "Test 2",
"url": "http://www.yahoo.com/news link...",
"description": "news link Link Description"
}
}
]
}
},
{
"Website": "Testing 2",
"Description": "Content from google ",
"LinkGroup": {
"entry": [
{
"linkType": "information",
"Link": {
"title": "Test1",
"url": "http://google.com",
"description": "my Link Description"
}
},
{
"linkType": "news link",
"Link": {
"title": "Test 2",
"url": "http://www.google.com/news link...",
"description": "news link Link Description"
}
}
]
}
},
I was earlier able to parse just the entry items and used it on a templated widget. I would now like to use the Website and Description object within my widget. Instead of the entry array object I tried to parse the Result object and tried to access the entry. Looking at the console log I see it stops when it tries to get the entry value. I am wondering how to parse it so I can first get the website and description and then add the entry items within that.
This is my html widget code
<div><span title="${Link.description}">${Link.description</span>/div> <br />
${Link.title}<br />
and I parse the json with this code
request("js/my/data/sample.json", {
handleAs: "json"}).then(function(jsonResults){
arrayUtil.forEach(jsonResults.LinksGroup, function(List)
{arrayUtil.forEach(List.LinksGroup.entry, function(Ientry){
var widget = new support(Ientry).placeAt(authorContainer);
});});
I found the answer. I used another widget within the array before the entry object which did the trick.