我试图使用HTTPie解析一些嵌套的JSON对象,但是我找不到方法。很清楚如何发送JSON对象,但不发送嵌套对象,例如
{“用户”:{“名称”:“约翰”“年龄”:10 }}
发布于 2016-05-17 03:21:35
2022年1月发布的HTTPie 3.0更新:
现在可以使用HTTPie语言对嵌套的JSON提供内置支持:
$ http pie.dev/post \
tool[name]=HTTPie \
tool[about][homepage]=httpie.io \
tool[about][mission]='Make APIs simple and intuitive' \
tool[platforms][]=terminal \
tool[platforms][]=desktop \
tool[platforms][]=web \
tool[platforms][]=mobile {
"tool": {
"name": "HTTPie",
"about": {
"mission": "Make APIs simple and intuitive",
"homepage": "httpie.io"
},
"platforms": [
"terminal",
"desktop",
"web",
"mobile"
]
}
}您可以在docs:https://httpie.io/docs/cli/nested-json中了解有关嵌套JSON的更多信息
对HTTPie的旧答案超过3.0:
你可以stdin
$ echo '{ "user": { "name": "john", "age": 10 } }' | http httpbin.org/post或:=
$ http httpbin.org/post user:='{"name": "john", "age": 10 }'发布于 2016-10-27 12:09:13
我喜欢这样:
$ http PUT localhost:8080/user <<<'{ "user": { "name": "john", "age": 10 }}'它更可取,因为它具有与相关命令相同的前缀,因此在bash中使用Ctrl+R查找命令很方便:
$ http localhost:8080/user/all
$ http GET localhost:8080/user/all # the same as the previous
$ http DELETE localhost:8080/user/234如果您有fishshell (它没有这里的Strings ),我可以提出以下解决方法:
~> function tmp; set f (mktemp); echo $argv > "$f"; echo $f; end
~> http POST localhost:8080/user < (tmp '{ "user": { "name": "john", "age": 10 }}')发布于 2020-08-10 16:15:13
httpie中提到的另一种方法是使用JSON文件;对于更详细和嵌套更深的有效负载,这种方法非常有效。
http POST httpbin.org/post < post.jsonhttps://stackoverflow.com/questions/37215565
复制相似问题