Skip to content

deleting a key inside of an object inside an array doesn't work as expected #169

Open
@sebastiandeutsch

Description

@sebastiandeutsch

I'm using the json from the readme:

json = <<-HERE_DOC
{"store":
  {"bicycle":
    {"price":19.95, "color":"red"},
    "book":[
      {"price":8.95, "category":"reference", "title":"Sayings of the Century", "author":"Nigel Rees"},
      {"price":12.99, "category":"fiction", "title":"Sword of Honour", "author":"Evelyn Waugh"},
      {"price":8.99, "category":"fiction", "isbn":"0-553-21311-3", "title":"Moby Dick", "author":"Herman Melville","color":"blue"},
      {"price":22.99, "category":"fiction", "isbn":"0-395-19395-8", "title":"The Lord of the Rings", "author":"Tolkien"}
    ]
  }
}
HERE_DOC

and trying to remove an attribute of an arrayobject

JsonPath.for(json).delete("$.store.book[0].category")

Unfortunately it removes the complete book object:

{"store"=>
  {"bicycle"=>{"price"=>19.95, "color"=>"red"},
   "book"=>
    [{"price"=>12.99, "category"=>"fiction", "title"=>"Sword of Honour", "author"=>"Evelyn Waugh"},
     {"price"=>8.99, "category"=>"fiction", "isbn"=>"0-553-21311-3", "title"=>"Moby Dick", "author"=>"Herman Melville", "color"=>"blue"},
     {"price"=>22.99, "category"=>"fiction", "isbn"=>"0-395-19395-8", "title"=>"The Lord of the Rings", "author"=>"Tolkien"}]}}

expected:

{"store":
  {"bicycle":
    {"price":19.95, "color":"red"},
    "book":[
      {"price":8.95, "title":"Sayings of the Century", "author":"Nigel Rees"},
      {"price":12.99, "category":"fiction", "title":"Sword of Honour", "author":"Evelyn Waugh"},
      {"price":8.99, "category":"fiction", "isbn":"0-553-21311-3", "title":"Moby Dick", "author":"Herman Melville","color":"blue"},
      {"price":22.99, "category":"fiction", "isbn":"0-395-19395-8", "title":"The Lord of the Rings", "author":"Tolkien"}
    ]
  }
}

@Skarlso any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions