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

deepscan issue #15

Closed
edodekel opened this issue Jul 30, 2020 · 6 comments
Closed

deepscan issue #15

edodekel opened this issue Jul 30, 2020 · 6 comments

Comments

@edodekel
Copy link

edodekel commented Jul 30, 2020

two similar jsonpath queries give different results:

data:=[]byte({ "apiVersion": "v1", "kind": "Pod", "spec": { "containers": [ { "name": "c1", "image": "busybox", "resources": { "limits": { "cpu": "2" } } }, { "name": "c2", "image": "busybox", "resources": { "limits": { "cpu": "2" } } } ] } })

jsonslice.Get(data, "$.spec.containers[:]")

gives the expected result:

[{
"name": "c1",
"image": "busybox",
"resources": {
"limits": {
"cpu": "2"
}
}
},{
"name": "c2",
"image": "busybox",
"resources": {
"limits": {
"cpu": "2"
}
}
}]

BUT:

jsonslice.Get(data, "$..spec.containers[:]")
gives:

[{
"containers": [
{
"name": "c1",
"image": "busybox",
"resources": {
"limits": {
"cpu": "2"
}
}
},
{
"name": "c2",
"image": "busybox",
"resources": {
"limits": {
"cpu": "2"
}
}
}
]
}]

@bhmj
Copy link
Owner

bhmj commented Aug 7, 2020

Working on a fix

@bhmj bhmj mentioned this issue Sep 22, 2020
@bhmj
Copy link
Owner

bhmj commented Sep 22, 2020

Fixed in release 1.0.5

@edodekel
Copy link
Author

thanks

@bhmj bhmj closed this as completed Sep 23, 2020
@edodekel
Copy link
Author

jsonslice.Get(data, "$.spec.containers[:]")

gives the expected result:

[{
"name": "c1",
"image": "busybox",
"resources": {
"limits": {
"cpu": "2"
}
}
},{
"name": "c2",
"image": "busybox",
"resources": {
"limits": {
"cpu": "2"
}
}
}]

BUT:

jsonslice.Get(data, "$..spec.containers[:]")

gives double square brackets.

[[{
"name": "c1",
"image": "busybox",
"resources": {
"limits": {
"cpu": "2"
}
}
},{
"name": "c2",
"image": "busybox",
"resources": {
"limits": {
"cpu": "2"
}
}
}]]

is it the expected result for deep scan?

@bhmj bhmj reopened this Sep 23, 2020
@bhmj
Copy link
Owner

bhmj commented Sep 23, 2020

It is, because $.spec.containers[:] gives you a single array of all elements of containers, but $..spec.containers[:] scans the input for all the spec.containers[:] entries (there can be many of them) and puts them all in array. Each entry happens to be an array as stated above. In this particular case there is only one entry found, thus [ [...] ].

@edodekel
Copy link
Author

so it is as designed. thanks

@bhmj bhmj closed this as completed Sep 23, 2020
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