1

I'd like to create a string of ISBNs from a JSON object to search multiple books in Google Books.

I can get the ISBNs by parsing Google Books' JSON with this path:

volumeInfo.industryIdentifiers[0].identifier

(Here I'm doing that to get a simple book list: jsfiddle.net/LyNfX )

How do I string together each value in order to get this query structure, where each ISBN is preceded by "isbn:", and after the first one they are separated by "OR"

https://www.google.com/search?btnG=Search+Books&tbm=bks&q=Springfield+isbn:1416549838+OR+isbn:068482535X+OR+isbn:0805093079+OR+isbn:0306810328
4
  • How do you get the second ISBN? Commented Feb 4, 2013 at 15:25
  • is the fiddle I use the jquery template plugin and {{each}} Commented Feb 4, 2013 at 15:44
  • Have you got this working? Commented Feb 4, 2013 at 15:58
  • see the fiddle. It successfully lists the info for each book. what I was looking for was creating a string from that same info. Commented Feb 4, 2013 at 16:33

2 Answers 2

3

Starting from an array of ISBN strings called list:

list.map(function(v){return "isbn:"+v;}).join("+OR+")

As for building your list of ISBN's which I understand to be the identifier prop in your industryIdentifiers (if industryIdentifier is a bona fide Array):

var list = [];
volumeInfo.industryIdentifiers.forEach(function(e,i){list.push(e.identifier);});

You could also just build the final string in one fell swoop and not build an array at all, but this means extra logic to prevent inserting an extra delimiter (+OR+ being the delimiter)

var output = "";
volumeInfo.industryIdentifiers.forEach(function(e,i){output += "isbn:"+e.identifier+"+OR+";});
output.slice(0,-4); // clear out last +OR+
Sign up to request clarification or add additional context in comments.

6 Comments

great. how would I get the volumeInfo.industryIdentifiers.identifier 's into the array to start?
I don't know what the format of that is. Could you post it or something?
in my fiddle [jsfiddle.net/LyNfX] , I use the jQuery template plugin to create html for each book like this: var mylist = "{{each items}}" + "<div class=book id=" + theid + ">" + "<p><b>title</b> is ${volumeInfo.title}" + "<p><b>author</b> is ${volumeInfo.authors}" + "<p><b>isbn10</b> is ${volumeInfo.industryIdentifiers[0].identifier}" + "</div>{{/each}}";
so what I need now is to get each volumeInfo.industryIdentifiers.identifier into an array, rather than printing it into html. then I can do your list.map ... on that array -- if I'm understanding correctly?
on this related q, it looks like this was the approach -- is this on the right track? for(i=0;i<data.length;i++){ things[i]=[data[i].id,String(data[i].username),String(data[i].things)]; stackoverflow.com/questions/3442487/…
|
1
var arrayOfISBNs = [123,456,789...];
var result = "isbn:" + arrayOfISBNs.join(" OR isbn:")

Just use array join.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.