Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在jenkins Shell中解析json文件时发生jq错误_Json_Error Handling_Compilation_Runtime Error_Jq - Fatal编程技术网

在jenkins Shell中解析json文件时发生jq错误

在jenkins Shell中解析json文件时发生jq错误,json,error-handling,compilation,runtime-error,jq,Json,Error Handling,Compilation,Runtime Error,Jq,我想从json解析文件路径的值。在通过jq解析它时,发现了关于未在顶层定义的问题。请在下面查找json详细信息和错误: "environment":{ "stage":{ "testing":[ { "tag":"1.0" "filepath":"C:/test/conf" "hostname":"test" }]}} **command Used in Execute shell:** jq -r ".'e

我想从json解析文件路径的值。在通过jq解析它时,发现了关于未在顶层定义的问题。请在下面查找json详细信息和错误:

"environment":{
             "stage":{
                       "testing":[
{
 "tag":"1.0"
  "filepath":"C:/test/conf"
   "hostname":"test"
}]}}

**command Used in Execute shell:**
 jq -r ".'environment.stage.testing[].filePath' env.json

**Error Faced**:
jq: error: environments/0 is not defined at <top-level>, line 1:
environment.stage.testing[].filePath
jq: 1 compile error

TIA
“环境”:{
“阶段”:{
“测试”:[
{
“标签”:“1.0”
“文件路径”:“C:/test/conf”
“主机名”:“测试”
}]}}
**执行shell中使用的命令:**
jq-r.“'environment.stage.testing[].filePath'env.json”
**面临错误**:
jq:错误:未在第1行定义环境/0:
environment.stage.testing[]文件路径
jq:1编译错误
短暂性脑缺血发作

如果您通过添加逗号来分隔元素
标记
文件路径
主机名
,从而修复了JSON文件:

{
  "environment": {
    "stage": {
      "testing": [
        {
          "tag": "1.0",
          "filepath": "C:/test/conf",
          "hostname": "test"
        }
      ]
    }
  }
}
您可以使用此
jq
命令:

jq -r '.environment.stage.testing[].filepath' env.json

注意命令中的关键字
filepath
而不是
filepath

提供了通过添加逗号分隔元素
标记
文件路径
主机名
来修复JSON文件的方法:

{
  "environment": {
    "stage": {
      "testing": [
        {
          "tag": "1.0",
          "filepath": "C:/test/conf",
          "hostname": "test"
        }
      ]
    }
  }
}
您可以使用此
jq
命令:

jq -r '.environment.stage.testing[].filepath' env.json
注意命令中的关键字
filepath
而不是
filepath

  • 发布的数据符合的要求,并可通过以下方式转换为JSON:

    hjson-j

  • jq过滤器包含
    .filePath
    ,而HJSON只包含一个名为“filePath”的键

  • 与已发布数据对应的过滤器为:

    .environment.stage.testing[]文件路径

  • 综合以上各项:

    $ hjson -j < so-jenkins-shell.hjson |
      jq -r '.environment.stage.testing[].filepath'
    C:/test/conf
    
    $hjson-j
  • 发布的数据符合的要求,并可通过以下方式转换为JSON:

    hjson-j

  • jq过滤器包含
    .filePath
    ,而HJSON只包含一个名为“filePath”的键

  • 与已发布数据对应的过滤器为:

    .environment.stage.testing[]文件路径

  • 综合以上各项:

    $ hjson -j < so-jenkins-shell.hjson |
      jq -r '.environment.stage.testing[].filepath'
    C:/test/conf
    
    $hjson-j
    元素已经用逗号分隔了。而且文件路径值也被更正了,仍然遇到相同的错误将
    {
    放在
    之前的“环境”
    }
    放在文件的末尾。然后命令将起作用。是的,添加了{}在环境之前和之后,这也没有取得成功。很难看到您在输入文件中更改了什么。但可以肯定的是,如果您从本文中获取JSON数据,该命令将起作用。这可能是输入数据中的一个输入错误。元素已仅用逗号分隔。而且,该文件路径值已被更正,仍然会遇到错误ame ERROR将一个
    {
    放在
    “环境”
    之前,并将一个
    }
    放在文件末尾。然后该命令将起作用。是的,添加了{}在环境之前和之后,这也没有取得成功。很难看到您在输入文件中更改了什么。但可以肯定的是,如果您从本文获取JSON数据,该命令将起作用。这可能是输入数据中的输入错误。