我将curl输出通过管道传输到jq:https://stedolan.github.io/jq/,在我尝试使用选择过滤器之前,一切都很正常。
这个过滤器在他们的在线工具https://jqplay.org/中和我下载文件后的命令行实验中都工作得很好。
只有当我尝试通过管道将curl输出直接传输到jq时,才会出现此问题。
这将失败:
i71178@SLCITS-L2222:~/next-gen/mongodb$ curl 'http://fhirtest.uhn.ca/baseDstu3/Patient?_format=json&_count=50&_pretty=false&_summary=data' | jq-linux64 --unbuffered -r -c '.link[] | select(.relation == next) | .url' | head -3
jq: error: next/0 is not defined at <top-level>, line 1:
.link[] | select(.relation == next) | .url
jq: 1 compile error
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2421 0 2421 0 0 2413 0 --:--:-- 0:00:01 --:--:-- 2413
curl: (23) Failed writing body (1675 != 2736)
i71178@SLCITS-L2222:~/next-gen/mongodb$ 这可以很好地工作:
i71178@SLCITS-L2222:~/next-gen/mongodb$ curl 'http://fhirtest.uhn.ca/baseDstu3/Patient?_format=json&_count=50&_pretty=false&_summary=data' | jq-linux64 --unbuffered -r -c '.link[] | .url' | head -3 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 46801 0 46801 0 0 66256 0 --:--:-- --:--:-- --:--:-- 66290
http://fhirtest.uhn.ca/baseDstu3/Patient?_count=50&_format=json&_pretty=false&_summary=data
http://fhirtest.uhn.ca/baseDstu3?_getpages=e73ba3b4-cc7e-4028-8679-b5da1f9cbdd1&_getpagesoffset=50&_count=50&_format=json&_bundletype=searchset
i71178@SLCITS-L2222:~/next-gen/mongodb$ 对于上下文,这是通过管道连接到选择过滤器的内容:
i71178@SLCITS-L2222:~/next-gen/mongodb$ curl 'http://fhirtest.uhn.ca/baseDstu3/Patient?_format=json&_count=50&_pretty=false&_summary=data' | jq-linux64 --unbuffered -r -c '.link[]' | head -3
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 46801 0 46801 0 0 64411 0 --:--:-- --:--:-- --:--:-- 64375
{"relation":"self","url":"http://fhirtest.uhn.ca/baseDstu3/Patient?_count=50&_format=json&_pretty=false&_summary=data"}
{"relation":"next","url":"http://fhirtest.uhn.ca/baseDstu3?_getpages=00952912-c9ab-47ca-826c-200bddffe617&_getpagesoffset=50&_count=50&_format=json&_bundletype=searchset"}
i71178@SLCITS-L2222:~/next-gen/mongodb$ 我真的很感谢这里的任何帮助。
谢谢!
发布于 2016-09-13 06:24:59
问题很明显出在你的select过滤器上:
select(.relation == next)我想你的意思是:
select(.relation == "next")更安全的方法是:
select(.relation? == "next")https://stackoverflow.com/questions/39459308
复制相似问题