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

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

Open
sebastiandeutsch opened this issue Oct 23, 2024 · 1 comment

Comments

@sebastiandeutsch
Copy link

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?

@Skarlso
Copy link
Collaborator

Skarlso commented Oct 24, 2024

Hello.

No idea, sorry. I haven't been a maintainer of this project for over 4 years. :D

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