小编Col*_*gan的帖子

使用jq解析JSON字符串

我试图jq解析一个JSON结构,如:

{
  "a" : 1,
  "b" : 2,
  "c" : "{\"id\":\"9ee ...\",\"parent\":\"abc...\"}\n"
}
Run Code Online (Sandbox Code Playgroud)

也就是说,JSON中的元素是带有转义json的字符串.

所以,我有一些东西 $ jq [.c] myFile.json | jq [.id]

但那次崩溃了 jq: error: Cannot index string with string

这是因为.c的输出是一个字符串,而不是更多的JSON.如何让jq解析这个字符串?

我最初的解决方案是使用sed来替换所有的转义字符(\":\",\",\"\"),但这很麻烦,我认为有一种方法jq可以做到这一点吗?

谢谢!

编辑:此外,这里提供的jq版本是:

$ jq --version
jq version 1.3
Run Code Online (Sandbox Code Playgroud)

我想我可以根据需要更新它.

string json escaping sed jq

56
推荐指数
2
解决办法
2万
查看次数

nginx proxy_pass 正在设置响应端口

我的 Nginx 配置类似于:

server {
    listen 80;
    listen 443;
    server_name api.mysite.dev;

    location / {

        proxy_set_header Host "api.mysite.dev";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass  $scheme://127.0.0.1:8001;
    }

}

server {
    listen 80;
    listen 443;
    server_name mysite.dev www.mysite.dev;

    # Forward all /api/ requests ti api.mysite.dev
    # sadly need to keep this around for backwards compatibility
    location /api/ {
        proxy_set_header Host "api.mysite.dev";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass $scheme://127.0.0.1:8001/;

    }
    # The proxy_pass here ends up putting the port (8002) in the response URL.
    location / {
        proxy_set_header …
Run Code Online (Sandbox Code Playgroud)

proxy reverse-proxy nginx http-headers

4
推荐指数
1
解决办法
3万
查看次数

标签 统计

escaping ×1

http-headers ×1

jq ×1

json ×1

nginx ×1

proxy ×1

reverse-proxy ×1

sed ×1

string ×1