37

I'm trying to get the details of Amazon product from its ASIN. The product API allows to do a Itemlookup with ASIN, but the return value is in XML.

I want to do this call for Itemlookup from client side, so would like to do a JSONP call, which I couldn't find.

I found some articles on the web to convert the XML to JSON format using XSLT stylesheet:

(a) https://bitbucket.org/basti/python-amazon-product-api/src/tip/examples/json-results.py

I tried using this python-amazon-product-api and this example, but I couldn't get a JSON return.

(b) http://www.kokogiak.com/gedankengang/2006/05/consuming-amazons-web-api-directly.html

The request I tried to send is:

http://xml-us.amznxslt.com/onca/xml?AWSAccessKeyId=[ACCESS KEY]&AssociateTag=[ASSOCIATE TAG]&ContentType=text%2Fjavascript&IdType=ASIN&ItemId=B008IEGS9W&Operation=ItemLookup&ResponseGroup=Images%2CItemAttributes&Service=AWSECommerceService&Style=http%3A%2F%2Fforums.delphiforums.com%2Fdelphidocsz%2Famazon%2Fjson.xsl&Timestamp=2012-09-04T06%3A40%3A11Z&Signature=AGOqXvVSeMp3YyVkT4mGNXVx0cFGG%2Bh%2FdAebevbbF9o%3D

Please help with getting a JSON format with Amazon product API.


The OP can run this style-sheet (input document not used) to determine his XSLT version.

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  exclude-result-prefixes="xsl msxsl">
<xsl:output method="html" indent="yes"/>

<xsl:template match="/">
  <html>
    <head><title>About your XSLT Processor</title></head> 
   <body>
     <ul>
       <li>xsl:version=<xsl:value-of select="system-property('xsl:version')" /></li>
       <li>xsl:vendor=<xsl:value-of select="system-property('xsl:vendor')" /></li>
       <li>xsl:vendor-url=<xsl:value-of select="system-property('xsl:vendor-url')" /></li>
       <li>xsl:product-name=<xsl:value-of select="system-property('xsl:product-name')" /></li>
       <li>xsl:product-version=<xsl:value-of select="system-property('xsl:product-version')" /></li>
       <li>xsl:is-schema-aware=<xsl:value-of select="system-property('xsl:is-schema-aware')" /></li>
       <li>xsl:supports-serialization=<xsl:value-of select="system-property('xsl:supports-serialization')" /></li>
       <li>xsl:supports-backwards-compatibility=<xsl:value-of select="system-property('xsl:supports-backwards-compatibility')" /></li>
       <li>msxsl:version=<xsl:value-of select="system-property('msxsl:version')" /></li>
     </ul>  
   </body>  
 </html>  
</xsl:template>
      
</xsl:stylesheet>
    
starball
  • 20,030
  • 7
  • 43
  • 238
thomastinu
  • 399
  • 2
  • 5
  • 5
  • Please supply a sample of the return value XML, and your particular required JSON format. It should then be possible to write an XSLT style-sheet to transform it into JSON. What version of XSLT can you use? 1.0? or 2.0? – Sean B. Durkin Sep 04 '12 at 07:23
  • Please find the XML response at https://gist.github.com/3626354 . I would like to extract the product Title, details page link, the medium image of the product. I'm not sure of the version of the XSLT. How to find it out? – thomastinu Sep 04 '12 at 21:06
  • Please run the stylesheet that I have included, and report results. – Sean B. Durkin Sep 05 '12 at 00:43
  • Also, given the document you have linked, please list the JSON output that you would expect. – Sean B. Durkin Sep 05 '12 at 00:48
  • And what if the Title contains a double quote (") character? Will you be satisfied with a simple solution that ignores this possiblity? Or do you want a robust solution that JSON encodes values (that is to say escapes the double quotes)? (Refer Max Shawabkeh's answer to http://stackoverflow.com/questions/2732409) – Sean B. Durkin Sep 05 '12 at 01:38
  • +1 Any resolution to this question? – Anthony Mar 08 '13 at 10:55
  • The question still lacks what the desired JSON output format it. A simple Google search will provide hits to general XML->JSON conversion, but such solutions may be too general in this case. As for things like double quotes (assuming a custom JSON output is desired), you can use regex if using XSLT 2.0. If stuck with XSLT 1.0, see [http://stackoverflow.com/a/7523245/719934](http://stackoverflow.com/a/7523245/719934). – ewh Mar 08 '13 at 20:18
  • @thomastinu, Please, *edit* the question and provide: 1) the XML document you have (from AWS); and 2) The exact JSON object you want to have. – Dimitre Novatchev Mar 09 '13 at 15:49
  • @thomastinu if the answer below worked for you, consider accepting the answer, and marking the question as resolved. – SashaZd Jan 18 '17 at 18:12

2 Answers2

6

Try either of these ::

  1. Amazon JSON API - This is a ruby webservice to pass through requests and translate the responses to JSON.
  2. Try any of these Javascript functions to convert the XML you already have into JSON :
    1. http://goessner.net/download/prj/jsonxml/
    2. http://davidwalsh.name/convert-xml-json
    3. http://www.fyneworks.com/jquery/xml-to-json/
    4. http://www.thomasfrank.se/xml_to_json.html

I've tried thomasfrank myself. Its easy and works well :)

Max Parke
  • 3
  • 1
SashaZd
  • 3,315
  • 1
  • 26
  • 48
0

(disclosure) I’m Max and I’m a cofounder of Zinc (zinc.io). Our API produces a JSON response for both pricing and the product details page. Here’s a typical response for ASIN details: https://www.dropbox.com/s/peccdc1m2j34e0d/B018QPI98A.json?dl=0. If you're interested, see here: docs.zincapi.com

maxko87
  • 2,892
  • 4
  • 28
  • 43