我正在尝试使用 HTTPie 解析以发送一些嵌套的 JSON 对象,但我找不到如何。很清楚如何发送 JSON 对象而不是嵌套对象,例如
{ "user": { "name": "john" "age": 10 } }
最佳答案
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"
]
}
}
您可以在文档中了解有关嵌套 JSON 的更多信息:https://httpie.io/docs/cli/nested-json
HTTPie 3.0 之前的旧答案:
您可以pass the whole JSON via stdin
:
$ echo '{ "user": { "name": "john", "age": 10 } }' | http httpbin.org/post
或specify the raw JSON as value with :=
:
$ http httpbin.org/post user:='{"name": "john", "age": 10 }'
https://stackoverflow.com/questions/37215565/