-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
when parsing a json array, [] object yielded at end #7
Comments
Issue is caused by a bug that values within an array were handled as if they have keys (namely the previous key in the JSON object) while they should not have keys at all. |
Issue is fixed in v1.1.1. Please verify and close this issue if you're satisfied. |
now I'm only getting the first object in the array |
What do you mean? |
I see what you mean, hang on.. |
input: {
"kind": "ServiceList",
"apiVersion": "v1",
"metadata": {
"selfLink": "/api/v1/services",
"resourceVersion": "59"
},
"items": [
{
"metadata": {
"name": "kubernetes",
"namespace": "default",
"selfLink": "/api/v1/services/kubernetes?namespace=default",
"uid": "016e9dcd-ce39-11e4-ac24-3c970e4a436a",
"resourceVersion": "6",
"creationTimestamp": "2015-03-19T15:08:16+02:00",
"labels": {
"component": "apiserver",
"provider": "kubernetes"
}
},
"spec": {
"port": 443,
"protocol": "TCP",
"selector": null,
"clusterIP": "10.0.0.2",
"containerPort": 0,
"sessionAffinity": "None"
},
"status": {}
},
{
"metadata": {
"name": "kubernetes-ro",
"namespace": "default",
"selfLink": "/api/v1/services/kubernetes-ro?namespace=default",
"uid": "015b78bf-ce39-11e4-ac24-3c970e4a436a",
"resourceVersion": "5",
"creationTimestamp": "2015-03-19T15:08:15+02:00",
"labels": {
"component": "apiserver",
"provider": "kubernetes"
}
},
"spec": {
"port": 80,
"protocol": "TCP",
"selector": null,
"clusterIP": "10.0.0.1",
"containerPort": 0,
"sessionAffinity": "None"
},
"status": {}
}
]
} output:
only the first object is yielded |
i am also experiencing another new bug: certain keys are rendered as input: {
"kind": "PodList",
"apiVersion": "v1",
"metadata": {
"selfLink": "/api/v1/pods",
"resourceVersion": "1315"
},
"items": [
{
"metadata": {
"name": "redis-master3",
"namespace": "default",
"selfLink": "/api/v1/pods/redis-master3?namespace=default",
"uid": "1da148b4-cef5-11e4-ac24-3c970e4a436a",
"resourceVersion": "1301",
"creationTimestamp": "2015-03-20T13:34:48+02:00",
"labels": {
"mylabel": "mylabelvalue",
"role": "pod"
}
},
"spec": {
"volumes": null,
"containers": [
{
"name": "master",
"image": "dockerfile/redis",
"ports": [
{
"hostPort": 6379,
"containerPort": 6379,
"protocol": "TCP"
}
],
"resources": {
"limits": {
"cpu": "100m"
}
},
"terminationMessagePath": "/dev/termination-log",
"imagePullPolicy": "IfNotPresent",
"securityContext": {
"capabilities": {}
}
},
{
"name": "php-redis",
"image": "kubernetes/example-guestbook-php-redis",
"ports": [
{
"hostPort": 8000,
"containerPort": 80,
"protocol": "TCP"
}
],
"resources": {
"limits": {
"cpu": "100m",
"memory": "50000000"
}
},
"terminationMessagePath": "/dev/termination-log",
"imagePullPolicy": "IfNotPresent",
"securityContext": {
"capabilities": {}
}
}
],
"restartPolicy": {
"always": {}
},
"dnsPolicy": "ClusterFirst"
},
"status": {
"phase": "Pending"
}
}
]
} output: {"metadata"=>{"name"=>"redis-master3", "namespace"=>"default", "selfLink"=>"/api/v1/pods/redis-master3?namespace=default", "uid"=>"1da148b4-cef5-11e4-ac24-3c970e4a436a", "resourceVersion"=>"1301", "creationTimestamp"=>"2015-03-20T13:34:48+02:00", "labels"=>{"mylabel"=>"mylabelvalue", "role"=>"pod"}}, "spec"=>{"volumes"=>nil, "labels"=>[{"name"=>"master", "image"=>"dockerfile/redis", nil=>[{"hostPort"=>6379, "containerPort"=>6379, "protocol"=>"TCP"}], "resources"=>{"limits"=>{"cpu"=>"100m"}}, "terminationMessagePath"=>"/dev/termination-log", "imagePullPolicy"=>"IfNotPresent", "securityContext"=>{"capabilities"=>{}}}, {"name"=>"php-redis", "image"=>"kubernetes/example-guestbook-php-redis", "securityContext"=>{"capabilities"=>{}}, "resources"=>{"limits"=>{"cpu"=>"100m", "memory"=>"50000000"}}, "terminationMessagePath"=>"/dev/termination-log", "imagePullPolicy"=>"IfNotPresent"}], "restartPolicy"=>{"always"=>{}}, "dnsPolicy"=>"ClusterFirst"}, "status"=>{"phase"=>"Pending"}} (notice the line |
Turns out the cause was identified correctly (values within an array were handled as if they have keys) but I made wrong assumptions regarding fixing it. v1.1.2 should be fine, I also added more tests covering handling of arrays. Please verify again. |
now i'm getting the whole object back as a single array. what I want to do is yield each object within the array one-by-one. is this possible with |
Since the However.. Input: #7 (comment)
Is this what you're looking for? Using v1.3.0 (latest). |
@thisismydesign I'm looking for the same output, but with the parameters |
e.g. with json body {
"kind": "ServiceList",
"apiVersion": "v1",
"metadata": {
"selfLink": "/api/v1/services",
"resourceVersion": "59"
},
"items1": [
{
"metadata": {
"name": "kubernetes",
"namespace": "default",
"selfLink": "/api/v1/services/kubernetes?namespace=default",
"uid": "016e9dcd-ce39-11e4-ac24-3c970e4a436a",
"resourceVersion": "6",
"creationTimestamp": "2015-03-19T15:08:16+02:00",
"labels": {
"component": "apiserver",
"provider": "kubernetes"
}
},
"spec": {
"port": 443,
"protocol": "TCP",
"selector": "null",
"clusterIP": "10.0.0.2",
"containerPort": 0,
"sessionAffinity": "None"
},
"status": {}
},
{
"metadata": {
"name": "kubernetes-ro",
"namespace": "default",
"selfLink": "/api/v1/services/kubernetes-ro?namespace=default",
"uid": "015b78bf-ce39-11e4-ac24-3c970e4a436a",
"resourceVersion": "5",
"creationTimestamp": "2015-03-19T15:08:15+02:00",
"labels": {
"component": "apiserver",
"provider": "kubernetes"
}
},
"spec": {
"port": 80,
"protocol": "TCP",
"selector": "null",
"clusterIP": "10.0.0.1",
"containerPort": 0,
"sessionAffinity": "None"
},
"status": {}
}
],
"items2": [
{
"metadata": {
"name": "kubernetes",
"namespace": "default",
"selfLink": "/api/v1/services/kubernetes?namespace=default",
"uid": "016e9dcd-ce39-11e4-ac24-3c970e4a436a",
"resourceVersion": "6",
"creationTimestamp": "2015-03-19T15:08:16+02:00",
"labels": {
"component": "apiserver",
"provider": "kubernetes"
}
},
"spec": {
"port": 443,
"protocol": "TCP",
"selector": "null",
"clusterIP": "10.0.0.2",
"containerPort": 0,
"sessionAffinity": "None"
},
"status": {}
},
{
"metadata": {
"name": "kubernetes-ro",
"namespace": "default",
"selfLink": "/api/v1/services/kubernetes-ro?namespace=default",
"uid": "015b78bf-ce39-11e4-ac24-3c970e4a436a",
"resourceVersion": "5",
"creationTimestamp": "2015-03-19T15:08:15+02:00",
"labels": {
"component": "apiserver",
"provider": "kubernetes"
}
},
"spec": {
"port": 80,
"protocol": "TCP",
"selector": "null",
"clusterIP": "10.0.0.1",
"containerPort": 0,
"sessionAffinity": "None"
},
"status": {}
}
]
} i'd like to yield the contents of |
Not possible unfortunately. The closest you can do is what you already did: get the I think this would be possible with JSONPath though. Like I mentioned in your PR I'll think about supporting it but not sure about the effort yet. |
that would defeat the purpose of using |
Just wanted to point out that depending on the dispersion of data under separate In any case: how important is this for you? Would you consider implementing your own solution or is it rather just nice to have? |
Actually.. since the
Probably easier than reinventing the wheel, at least for now. I plan to keep |
I was planning to do some refactoring and now was a great time to do it as it solves your issue. In v2.0.0 I created abstraction layers for the callback handler and conditions. This will allow
For your use case:
See also the new section of the README and this test case. |
cool! will try it out now |
@ilackarms any update? |
perfect! works well. thank you so much for the support |
Glad to hear that it's working. My pleasure. :) |
i've noticed that when i parse an array, after yielding each of the objects in the array, an empty array object
[]
is yielded at the endreproduce:
input:
parsing code:
result:
The text was updated successfully, but these errors were encountered: