【问题标题】:jq: error: syntax error, unexpected $end (Windows cmd shell quoting issues?)jq:错误:语法错误,意外 $end(Windows cmd shell 引用问题?)
【发布时间】:2018-10-30 13:43:35
【问题描述】:
type sols3json.json | jq-win64.exe  "[.[] | { "type": "FeatureCollection","features":[{  type: "Feature", "geometry":  {"type": "LineString","coordinates":  [  [.OpStartLongitude, .OpStartLatitude| tonumber],  [ .OpEndLongitude, .OpEndLatitude | tonumber] ]  },  properties: {name: .SolName}}]}"  > sols3.geojson

我得到 jq:error: syntax error, unexpected $end(Windows cmd shell 引用问题?) 我究竟做错了什么? 输出应该是这样的:

{
"type": "FeatureCollection",
"features": 
    [
    {
    "properties": {
    "ccaa": "CATALUNYA",
    "prov": "LLEIDA",
    "dir": "N-IIA/SOSES/TORRES DE SEGRE/ALCARRàS",
    "roadnumber": "A-2",
    "tmc": "E17+02413"
    },
    "geometry": {
    "coordinates": [
    [
    0.4714937,
    41.5420936
    ],
    [
    0.4891472,
    41.5497014
    ]
    ],
    "type": "LineString"
    },
    "type": "Feature"
    }
    ]
}

【问题讨论】:

  • 过滤器末尾缺少右方括号 ]
  • 为了检查您的过滤器是否有用,请添加相关文件sols3json.json的内容。
  • 如果我添加它,我会得到 jq: error: FeatureCollection/0 is not defined at , line 1:
  • 文件包含以下格式的数据:{ "TMC": "E17+02412", "ROADNUMBER": "A-2", "DIR": "E-90/AP-2/ BARCELONA-ZARAGOZA (SOSES)”、“PROV”:“LLEIDA”、“CCAA”:“CATALUNYA”、“StartLatitude”:“41.5368273”、“StartLongitude”:“0.4387071”、“EndLatitude”:“41.5388396”、“EndLongitude” ": "0.4638462" } 但属性名称不同
  • 您应该使用您想要的确切格式更新您的问题。链接外部页面不是提出好问题的正确方法

标签: json jq


【解决方案1】:

你的问题不太清楚,但我理解正确,这可能是你想要的。

如果您的输入文件是:

[
  {
    "TMC": "E17+02412",
    "ROADNUMBER": "A-2",
    "DIR": "E-90/AP-2/BARCELONA-ZARAGOZA (SOSES)",
    "PROV": "LLEIDA",
    "CCAA": "CATALUNYA",
    "StartLatitude": "41.5368273",
    "StartLongitude": "0.4387071",
    "EndLatitude": "41.5388396",
    "EndLongitude": "0.4638462"
  }
]

您可以使用此jq 过滤器过滤内容:

jq 'map({ type: "Feature", "geometry": {"type": "LineString","coordinates": [ [.StartLongitude, .StartLatitude| tonumber], [ .EndLongitude, .EndLatitude | tonumber] ] }, properties: {tmc: .TMC, roadnumber: .ROADNUMBER, dir: .DIR, prov: .PROV, ccaa: .CCAA}})' file

产生这个新的 JSON 数据:

[
  {
    "type": "Feature",
    "geometry": {
      "type": "LineString",
      "coordinates": [
        [
          0.4387071,
          41.5368273
        ],
        [
          0.4638462,
          41.5388396
        ]
      ]
    },
    "properties": {
      "tmc": "E17+02412",
      "roadnumber": "A-2",
      "dir": "E-90/AP-2/BARCELONA-ZARAGOZA (SOSES)",
      "prov": "LLEIDA",
      "ccaa": "CATALUNYA"
    }
  }
]

【讨论】:

  • 那是真的,但我需要创建一个 FeatureCollection(因为我有多个记录,如这里所述 doublebyteblog.wordpress.com/2015/02/16/csv-2-geojson )。
  • 所以完整的json输入格式是这样的 [ { "TMC": "E17+02412", "ROADNUMBER": "A-2", "DIR": "E-90/AP- 2/巴塞罗那-萨拉戈萨(SOSES)”,“PROV”:“LLEIDA”,“CCAA”:“CATALUNYA”,“StartLatitude”:“41.5368273”,“StartLongitude”:“0.4387071”,“EndLatitude”:“41.5388396”, "EndLongitude": "0.4638462" } ]
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-21
  • 2014-12-18
  • 2022-12-12
  • 1970-01-01
  • 2012-05-16
相关资源
最近更新 更多