首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Ansible解析JSON中的单引号

使用Ansible解析JSON中的单引号
EN

Stack Overflow用户
提问于 2022-11-18 08:09:11
回答 1查看 24关注 0票数 -1

我正在尝试运行一个带有单引号的JSON输入的Ansible剧本。运行剧本失败,出现以下错误。有没有办法解析一下单引号。到目前为止,我的错误越来越少。

代码语言:javascript
运行
复制
JSON: Expecting value: line 1 column 1 (char 0)

Syntax Error while loading YAML.
  expected <block end>, but found '<scalar>'

ERROR! We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: Expecting value: line 1 column 1 (char 0)

Syntax Error while loading YAML.
  expected <block end>, but found '<scalar>'

The error appears to be in line 161, column 69, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

            "logGroups": "aws_log_group_name",
            "query": "fields @timestamp, @message | parse @message 'GET *:4' as apiName | parse @message ':443* H' as backend | sort @timestamp desc | stats count() as count by backend | sort count desc"
                                                                    ^ here

杰森:

代码语言:javascript
运行
复制
{
    "type": "custom",
    "width": 24,
    "height": 18,
    "properties": {
        "params": {
            "region": "us-east-1",
            "logGroups": "aws_log_group",
            "query": "fields @timestamp, @message | parse @message 'GET *:4' as apiName | parse @message ':443* H' as backend | sort @timestamp desc | stats count() as count by backend | sort count desc"
        },
        "updateOn": {
            "refresh": true,
            "timeRange": true
        },
        "title": "ELB logs"
    }
}
EN

回答 1

Stack Overflow用户

发布于 2022-11-18 08:18:32

是有效的JSON

代码语言:javascript
运行
复制
shell> cat dashboard.json 
{
    "type": "custom",
    "width": 24,
    "height": 18,
    "properties": {
        "params": {
            "region": "us-east-1",
            "logGroups": "aws_log_group",
            "query": "fields @timestamp, @message | parse @message 'GET *:4' as apiName | parse @message ':443* H' as backend | sort @timestamp desc | stats count() as count by backend | sort count desc"
        },
        "updateOn": {
            "refresh": true,
            "timeRange": true
        },
        "title": "ELB logs"
    }
}

下面的剧本按预期工作。

代码语言:javascript
运行
复制
- hosts: localhost
  tasks:
    - include_vars:
        file: dashboard.json
        name: dashboard
    - debug:
        var: dashboard
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74486629

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档