Skip to content

Cannot read json stream using Reader() #105

Open
@EwanMe

Description

@EwanMe

I'm trying to read JSON from a stream using the New().Reader() method (I'm using the docker api). I want to read the same JSON value which will be continuously updated in a for loop. Using the following code my output is empty and my program will just hang in the loop forever.

resp, err := cli.ContainerStats(ctx, cont_id.String(), true)
if err != nil {
    panic(err)
}

jq := gojsonq.New().Reader(resp.Body)
	
if jq.Error() != nil {
    panic(jq.Errors())
}

for {
    value := jq.Find("myKey")
    fmt.Println(value)

}

For the sake of the example my JSON is just:

{
  "myKey": "myVal"
}

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