Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all matching items with nested array #15

Closed
wiltshirek opened this issue Mar 2, 2016 · 2 comments
Closed

all matching items with nested array #15

wiltshirek opened this issue Mar 2, 2016 · 2 comments

Comments

@wiltshirek
Copy link

hi,

I am trying to use the multiple matching items qry but experiencing an issue at a certain level in the json hierarchy. It seems to be related to an array or arrays opposed to an array of objects as follows (sorry for the annoyingly long snippet of json but I want to make this as easy as possible to debug).

var jsonQuery =require("json-query")
var data = '{"name":"product","attributes":{},"isSelfClosing":false,"parent":null,"children":["    ",{"name":"sku","attributes":{},"isSelfClosing":false,"children":["17447336"]},"    ",{"name":"productId","attributes":{},"isSelfClosing":false,"children":["2416800"]},"    ",{"name":"name","attributes":{},"isSelfClosing":false,"children":["Invitation to Forever - CD"]},"    ",{"name":"source","attributes":{},"isSelfClosing":false,"children":["bestbuy"]},"    ",{"name":"type","attributes":{},"isSelfClosing":false,"children":["Music"]},"    ",{"name":"startDate","attributes":{},"isSelfClosing":false,"children":["2008-04-22"]},"    ",{"name":"new","attributes":{},"isSelfClosing":false,"children":["false"]},"    ",{"name":"active","attributes":{},"isSelfClosing":false,"children":["true"]},"    ",{"name":"lowPriceGuarantee","attributes":{},"isSelfClosing":false,"children":["true"]},"    ",{"name":"activeUpdateDate","attributes":{},"isSelfClosing":false,"children":["2016-02-01T15:14:59"]},"    ",{"name":"regularPrice","attributes":{},"isSelfClosing":false,"children":["13.99"]},"    ",{"name":"salePrice","attributes":{},"isSelfClosing":false,"children":["13.99"]},"    ",{"name":"onSale","attributes":{},"isSelfClosing":false,"children":["false"]},"    ",{"name":"planPrice","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"priceWithPlan","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"advertisedPriceRestriction","attributes":{},"isSelfClosing":false,"children":["false"]},"    ",{"name":"minimumDisplayPrice","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"restrictedSalePrice","attributes":{},"isSelfClosing":false,"children":["13.99"]},"    ",{"name":"icrType","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"icrStartDate","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"icrEndDate","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"priceRestriction","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"priceUpdateDate","attributes":{},"isSelfClosing":false,"children":["2013-09-13T00:21:36"]},"    ",{"name":"digital","attributes":{},"isSelfClosing":false,"children":["false"]},"    ",{"name":"preowned","attributes":{},"isSelfClosing":false,"children":["false"]},"    ",{"name":"outletCenter","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"secondaryMarket","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"frequentlyPurchasedWith","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"relatedProducts","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"crossSell","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"salesRankShortTerm","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"salesRankMediumTerm","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"salesRankLongTerm","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"bestSellingRank","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"url","attributes":{},"isSelfClosing":false,"children":["http://www.bestbuy.com/site/invitation-to-forever-cd/17447336.p?id=2416800&skuId=17447336&cmp=RMX"]},"    ",{"name":"spin360Url","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"mobileUrl","attributes":{},"isSelfClosing":false,"children":["http://www.bestbuy.com/site/invitation-to-forever-cd/17447336.p?id=2416800&skuId=17447336&cmp=RMX&cmp=RMX"]},"    ",{"name":"affiliateUrl","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"addToCartUrl","attributes":{},"isSelfClosing":false,"children":["http://www.bestbuy.com/site/olspage.jsp?id=pcmcat152200050035&type=category&cmp=RMX&qvsids=17447336"]},"    ",{"name":"affiliateAddToCartUrl","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"linkShareAffiliateUrl","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"linkShareAffiliateAddToCartUrl","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"search","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"upc","attributes":{},"isSelfClosing":false,"children":["837792009887"]},"    ",{"name":"productTemplate","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"categoryPath","attributes":{},"isSelfClosing":false,"children":["      ",{"name":"category","attributes":{},"isSelfClosing":false,"children":["        ",{"name":"id","attributes":{},"isSelfClosing":false,"children":["cat00000"]},"        ",{"name":"name","attributes":{},"isSelfClosing":false,"children":["Best Buy"]},"      "]},"      ",{"name":"category","attributes":{},"isSelfClosing":false,"children":["        ",{"name":"id","attributes":{},"isSelfClosing":false,"children":["abcat0600000"]},"        ",{"name":"name","attributes":{},"isSelfClosing":false,"children":["Movies & Music"]},"      "]},"      ",{"name":"category","attributes":{},"isSelfClosing":false,"children":["        ",{"name":"id","attributes":{},"isSelfClosing":false,"children":["cat02001"]},"        ",{"name":"name","attributes":{},"isSelfClosing":false,"children":["Music (CDs & Vinyl)"]},"      "]},"      ",{"name":"category","attributes":{},"isSelfClosing":false,"children":["        ",{"name":"id","attributes":{},"isSelfClosing":false,"children":["cat02010"]},"        ",{"name":"name","attributes":{},"isSelfClosing":false,"children":["Rock"]},"      "]},"      ",{"name":"category","attributes":{},"isSelfClosing":false,"children":["        ",{"name":"id","attributes":{},"isSelfClosing":false,"children":["cat02673"]},"        ",{"name":"name","attributes":{},"isSelfClosing":false,"children":["Hard Rock"]},"      "]},"    "]},"    ",{"name":"lists","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"customerReviewCount","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"customerReviewAverage","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"customerTopRated","attributes":{},"isSelfClosing":false,"children":["false"]},"    ",{"name":"format","attributes":{},"isSelfClosing":false,"children":["CD"]},"    ",{"name":"freeShipping","attributes":{},"isSelfClosing":false,"children":["false"]},"    ",{"name":"freeShippingEligible","attributes":{},"isSelfClosing":false,"children":["true"]},"    ",{"name":"inStoreAvailability","attributes":{},"isSelfClosing":false,"children":["false"]},"    ",{"name":"inStoreAvailabilityText","attributes":{},"isSelfClosing":false,"children":["Store Pickup: Not Available"]},"    ",{"name":"inStoreAvailabilityTextHtml","attributes":{},"isSelfClosing":false,"children":["<b>Store Pickup:</b> Not Available"]},"    ",{"name":"inStoreAvailabilityUpdateDate","attributes":{},"isSelfClosing":false,"children":["2016-02-01T15:14:59"]},"    ",{"name":"itemUpdateDate","attributes":{},"isSelfClosing":false,"children":["2016-02-17T05:22:50"]},"    ",{"name":"onlineAvailability","attributes":{},"isSelfClosing":false,"children":["true"]},"    ",{"name":"onlineAvailabilityText","attributes":{},"isSelfClosing":false,"children":["Shipping: Usually leaves our warehouse in 1 business day"]},"    ",{"name":"onlineAvailabilityTextHtml","attributes":{},"isSelfClosing":false,"children":["<b>Shipping:</b> Usually leaves our warehouse in 1 business day"]},"    ",{"name":"onlineAvailabilityUpdateDate","attributes":{},"isSelfClosing":false,"children":["2016-02-01T15:14:59"]},"    ",{"name":"releaseDate","attributes":{},"isSelfClosing":false,"children":["2008-11-18"]},"    ",{"name":"shippingCost","attributes":{},"isSelfClosing":false,"children":["2.99"]},"    ",{"name":"shipping","attributes":{},"isSelfClosing":false,"children":["      ",{"name":"ground","attributes":{},"isSelfClosing":false,"children":["2.99"]},"      ",{"name":"secondDay","attributes":{},"isSelfClosing":false,"children":["10.99"]},"      ",{"name":"nextDay","attributes":{},"isSelfClosing":false,"children":["14.99"]},"      ",{"name":"vendorDelivery","attributes":{},"isSelfClosing":true,"children":[]},"    "]},"    ",{"name":"shippingLevelsOfService","attributes":{},"isSelfClosing":false,"children":["      ",{"name":"shippingLevelOfService","attributes":{},"isSelfClosing":false,"children":["        ",{"name":"serviceLevelId","attributes":{},"isSelfClosing":false,"children":["1"]},"        ",{"name":"serviceLevelName","attributes":{},"isSelfClosing":false,"children":["Standard"]},"        ",{"name":"unitShippingPrice","attributes":{},"isSelfClosing":false,"children":["2.99"]},"      "]},"      ",{"name":"shippingLevelOfService","attributes":{},"isSelfClosing":false,"children":["        ",{"name":"serviceLevelId","attributes":{},"isSelfClosing":false,"children":["3"]},"        ",{"name":"serviceLevelName","attributes":{},"isSelfClosing":false,"children":["Expedited"]},"        ",{"name":"unitShippingPrice","attributes":{},"isSelfClosing":false,"children":["10.99"]},"      "]},"      ",{"name":"shippingLevelOfService","attributes":{},"isSelfClosing":false,"children":["        ",{"name":"serviceLevelId","attributes":{},"isSelfClosing":false,"children":["5"]},"        ",{"name":"serviceLevelName","attributes":{},"isSelfClosing":false,"children":["Express"]},"        ",{"name":"unitShippingPrice","attributes":{},"isSelfClosing":false,"children":["14.99"]},"      "]},"    "]},"    ",{"name":"specialOrder","attributes":{},"isSelfClosing":false,"children":["false"]},"    ",{"name":"shortDescription","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"shortDescriptionHtml","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"class","attributes":{},"isSelfClosing":false,"children":["COMPACT DISC"]},"    ",{"name":"classId","attributes":{},"isSelfClosing":false,"children":["77"]},"    ",{"name":"subclass","attributes":{},"isSelfClosing":false,"children":["ROCK"]},"    ",{"name":"subclassId","attributes":{},"isSelfClosing":false,"children":["1001"]},"    ",{"name":"department","attributes":{},"isSelfClosing":false,"children":["VIDEO/COMPACT DISC"]},"    ",{"name":"departmentId","attributes":{},"isSelfClosing":false,"children":["8"]},"    ",{"name":"bestBuyItemId","attributes":{},"isSelfClosing":false,"children":["1324170"]},"    ",{"name":"productFamilies","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"manufacturer","attributes":{},"isSelfClosing":false,"children":["Prog Rock Records"]},"    ",{"name":"image","attributes":{},"isSelfClosing":false,"children":["http://images.bestbuy.com/BestBuy_US/images/products/1744/17447336_sa.jpg"]},"    ",{"name":"largeFrontImage","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"mediumImage","attributes":{},"isSelfClosing":false,"children":["http://images.bestbuy.com/BestBuy_US/images/products/1744/17447336fp.gif"]},"    ",{"name":"thumbnailImage","attributes":{},"isSelfClosing":false,"children":["http://images.bestbuy.com/BestBuy_US/images/products/1744/17447336_s.gif"]},"    ",{"name":"largeImage","attributes":{},"isSelfClosing":false,"children":["http://images.bestbuy.com/BestBuy_US/images/products/1744/17447336_sb.jpg"]},"    ",{"name":"alternateViewsImage","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"angleImage","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"backViewImage","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"energyGuideImage","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"leftViewImage","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"accessoriesImage","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"remoteControlImage","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"rightViewImage","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"topViewImage","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"albumTitle","attributes":{},"isSelfClosing":false,"children":["Invitation to Forever"]},"    ",{"name":"artistName","attributes":{},"isSelfClosing":false,"children":["Takara"]},"    ",{"name":"artistId","attributes":{},"isSelfClosing":false,"children":["BYPart66281"]},"    ",{"name":"originalReleaseDate","attributes":{},"isSelfClosing":false,"children":["2008-07-01"]},"    ",{"name":"parentalAdvisory","attributes":{},"isSelfClosing":false,"children":["false"]},"    ",{"name":"mediaCount","attributes":{},"isSelfClosing":false,"children":["1"]},"    ",{"name":"monoStereo","attributes":{},"isSelfClosing":false,"children":["Stereo"]},"    ",{"name":"studioLive","attributes":{},"isSelfClosing":false,"children":["Studio"]},"    ",{"name":"inStorePickup","attributes":{},"isSelfClosing":false,"children":["false"]},"    ",{"name":"friendsAndFamilyPickup","attributes":{},"isSelfClosing":false,"children":["false"]},"    ",{"name":"homeDelivery","attributes":{},"isSelfClosing":false,"children":["false"]},"    ",{"name":"quantityLimit","attributes":{},"isSelfClosing":false,"children":["3"]},"    ",{"name":"fulfilledBy","attributes":{},"isSelfClosing":false,"children":["BestBuy.com"]},"    ",{"name":"relatedNapsterSkus","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"relatedBestBuySkus","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"bundledIn","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"albumLabel","attributes":{},"isSelfClosing":false,"children":["Prog Rock Records"]},"    ",{"name":"genre","attributes":{},"isSelfClosing":false,"children":["Hard Rock"]},"    ",{"name":"dollarSavings","attributes":{},"isSelfClosing":false,"children":["0.00"]},"    ",{"name":"percentSavings","attributes":{},"isSelfClosing":false,"children":["0.0"]},"    ",{"name":"orderable","attributes":{},"isSelfClosing":false,"children":["Available"]},"    ",{"name":"shippingWeight","attributes":{},"isSelfClosing":false,"children":["0.25"]},"    ",{"name":"offers","attributes":{},"isSelfClosing":false,"children":["      ",{"name":"offer","attributes":{},"isSelfClosing":false,"children":["        ",{"name":"id","attributes":{},"isSelfClosing":false,"children":["148313"]},"        ",{"name":"heading","attributes":{},"isSelfClosing":true,"children":[]},"        ",{"name":"text","attributes":{},"isSelfClosing":false,"children":["Free Shipping on Orders $35 and Up"]},"        ",{"name":"url","attributes":{},"isSelfClosing":false,"children":["/site/offer/148313/pcmcat748301485567.c?id=pcmcat748301485567"]},"        ",{"name":"imageUrl","attributes":{},"isSelfClosing":true,"children":[]},"        ",{"name":"type","attributes":{},"isSelfClosing":false,"children":["special_offer"]},"        ",{"name":"startDate","attributes":{},"isSelfClosing":false,"children":["2016-01-02 23:45:00 -0600"]},"        ",{"name":"endDate","attributes":{},"isSelfClosing":false,"children":["2018-03-31 23:59:59 -0500"]},"      "]},"    "]},"    ",{"name":"marketplace","attributes":{},"isSelfClosing":false,"children":["false"]},"    ",{"name":"listingId","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"sellerId","attributes":{},"isSelfClosing":true,"children":[]},"    ",{"name":"shippingRestrictions","attributes":{},"isSelfClosing":true,"children":[]},"  "]}'
data = JSON.parse(data);



//offending line of code******
part1 = jsonQuery('children.[name=categoryPath].children[*name=category].children', {data: data}).value
console.log(part1)  
//which will return the following:
/*[ [ '        ',
    { name: 'id',
      attributes: {},
      isSelfClosing: false,
      children: [Object] },
    '        ',
    { name: 'name',
      attributes: {},
      isSelfClosing: false,
      children: [Object] },
    '      ' ],
  [ '        ',
    { name: 'id',
      attributes: {},
      isSelfClosing: false,
      children: [Object] },
    '        ',
    { name: 'name',
      attributes: {},
      isSelfClosing: false,
      children: [Object] },
    '      ' ],
  [ '        ',
    { name: 'id',
      attributes: {},
      isSelfClosing: false,
      children: [Object] },
    '        ',
    { name: 'name',
      attributes: {},
      isSelfClosing: false,
      children: [Object] },
    '      ' ],
  [ '        ',
    { name: 'id',
      attributes: {},
      isSelfClosing: false,
      children: [Object] },
    '        ',
    { name: 'name',
      attributes: {},
      isSelfClosing: false,
      children: [Object] },
    '      ' ],
  [ '        ',
    { name: 'id',
      attributes: {},
      isSelfClosing: false,
      children: [Object] },
    '        ',
    { name: 'name',
      attributes: {},
      isSelfClosing: false,
      children: [Object] },
    '      ' ] ]
*/

/*if you run the above snippet you will get a result but I can't seem to drill down any further than that.  I am trying to access the multiple 'children' objects but the [*xxxxx=xxxxx] feature doesn't seem to be working with an array or arrays.*/

Thanks in advance.

@mmckegg mmckegg closed this as completed in 4180e19 Mar 2, 2016
@mmckegg
Copy link
Collaborator

mmckegg commented Mar 2, 2016

@wiltshirek: Hey, thanks for reporting!

Should be fixed in v1.8.0.

jsonQuery('children.[name=categoryPath].children[*name=category].children.children', {data: data}).value

Now outputs:

[ 'cat00000',
  'Best Buy',
  'abcat0600000',
  'Movies & Music',
  'cat02001',
  'Music (CDs & Vinyl)',
  'cat02010',
  'Rock',
  'cat02673',
  'Hard Rock' ]

@wiltshirek
Copy link
Author

Awesome,

Thanks for the quick turn-around.

On Wed, Mar 2, 2016 at 2:51 AM, Matt McKegg notifications@github.com
wrote:

@wiltshirek https://github.com/wiltshirek: Hey, thanks for reporting!

Should be fixed in v1.8.0.

jsonQuery('children.[name=categoryPath].children[*name=category].children.children', {data: data}).value

Now outputs:

[ 'cat00000',
'Best Buy',
'abcat0600000',
'Movies & Music',
'cat02001',
'Music (CDs & Vinyl)',
'cat02010',
'Rock',
'cat02673',
'Hard Rock' ]


Reply to this email directly or view it on GitHub
#15 (comment).

Ken Wiltshire* |* Computer Applications Developer
5715 Ave N | Brooklyn, NY 11234

Direct (347) 675-5213

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants