将JSON转换为与Mapbox Studio兼容的GeoJSON

将JSON转换为与Mapbox Studio兼容的GeoJSON,json,dataset,mapbox,geojson,mapbox-gl-js,Json,Dataset,Mapbox,Geojson,Mapbox Gl Js,我正试图使用SpaceX API中的JSON,使用Mapbox GL在Mapbox地图上显示所有SpaceX发射场的位置。当我尝试将其加载到Mapbox Studio中的数据集中时,我得到一个错误,该错误显示:输入失败。第1行需要“类型”成员。 我假设这是由于JSON的结构方式,即它没有GeoJSON属性 如何轻松地调整此JSON并将其转换为与Mapbox一起使用的GeoJSON?您提供的JSON文件不是有效的GeoJSON。您可以在此处阅读有关格式规范的更多信息: 您可能需要一个小脚本来将Sp

我正试图使用SpaceX API中的JSON,使用Mapbox GL在Mapbox地图上显示所有SpaceX发射场的位置。当我尝试将其加载到Mapbox Studio中的数据集中时,我得到一个错误,该错误显示:输入失败。第1行需要“类型”成员。

我假设这是由于JSON的结构方式,即它没有GeoJSON属性


如何轻松地调整此JSON并将其转换为与Mapbox一起使用的GeoJSON?

您提供的JSON文件不是有效的GeoJSON。您可以在此处阅读有关格式规范的更多信息:

您可能需要一个小脚本来将SpaceX JSON文件转换为有效的GeoJSON。当前,单个记录如下所示:

{
  "id": "ccafs_slc_40",
  "full_name": "Cape Canaveral Air Force Station Space Launch Complex 40",
  "status": "active",
  "location": {
    "name": "Cape Canaveral",
    "region": "Florida",
    "latitude": 28.5618571,
    "longitude": -80.577366
  },
  "vehicles_launched": [
    "Falcon 9"
  ],
  "details": "SpaceX primary Falcon 9 launch pad, where all east coast Falcon 9s launched prior to the AMOS-6 anomaly. Initially used to launch Titan rockets for Lockheed Martin. Back online since CRS-13 on 2017-12-15."
}
{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [-80.577366, 28.5618571]
  },
  "properties": {
    "id": "ccafs_slc_40",
    "full_name": "Cape Canaveral Air Force Station Space Launch Complex 40",
    "status": "active",
    "location": {
      "name": "Cape Canaveral",
      "region": "Florida"
    },
    "vehicles_launched": ["Falcon 9"],
    "details":
      "SpaceX primary Falcon 9 launch pad, where all east coast Falcon 9s launched prior to the AMOS-6 anomaly. Initially used to launch Titan rockets for Lockheed Martin. Back online since CRS-13 on 2017-12-15."
  }
}
您可能需要的是一个几何图形类型为点的
功能
,如下所示:

{
  "id": "ccafs_slc_40",
  "full_name": "Cape Canaveral Air Force Station Space Launch Complex 40",
  "status": "active",
  "location": {
    "name": "Cape Canaveral",
    "region": "Florida",
    "latitude": 28.5618571,
    "longitude": -80.577366
  },
  "vehicles_launched": [
    "Falcon 9"
  ],
  "details": "SpaceX primary Falcon 9 launch pad, where all east coast Falcon 9s launched prior to the AMOS-6 anomaly. Initially used to launch Titan rockets for Lockheed Martin. Back online since CRS-13 on 2017-12-15."
}
{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [-80.577366, 28.5618571]
  },
  "properties": {
    "id": "ccafs_slc_40",
    "full_name": "Cape Canaveral Air Force Station Space Launch Complex 40",
    "status": "active",
    "location": {
      "name": "Cape Canaveral",
      "region": "Florida"
    },
    "vehicles_launched": ["Falcon 9"],
    "details":
      "SpaceX primary Falcon 9 launch pad, where all east coast Falcon 9s launched prior to the AMOS-6 anomaly. Initially used to launch Titan rockets for Lockheed Martin. Back online since CRS-13 on 2017-12-15."
  }
}
转换原始数组的每条记录后,需要将它们包装在
FeatureCollection
中,以便mapbox gl渲染:

{
  "type": "FeatureCollection",
  "features": [
    //...
  ]
}

您提供的JSON文件不是有效的GeoJSON。您可以在此处阅读有关格式规范的更多信息:

您可能需要一个小脚本来将SpaceX JSON文件转换为有效的GeoJSON。当前,单个记录如下所示:

{
  "id": "ccafs_slc_40",
  "full_name": "Cape Canaveral Air Force Station Space Launch Complex 40",
  "status": "active",
  "location": {
    "name": "Cape Canaveral",
    "region": "Florida",
    "latitude": 28.5618571,
    "longitude": -80.577366
  },
  "vehicles_launched": [
    "Falcon 9"
  ],
  "details": "SpaceX primary Falcon 9 launch pad, where all east coast Falcon 9s launched prior to the AMOS-6 anomaly. Initially used to launch Titan rockets for Lockheed Martin. Back online since CRS-13 on 2017-12-15."
}
{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [-80.577366, 28.5618571]
  },
  "properties": {
    "id": "ccafs_slc_40",
    "full_name": "Cape Canaveral Air Force Station Space Launch Complex 40",
    "status": "active",
    "location": {
      "name": "Cape Canaveral",
      "region": "Florida"
    },
    "vehicles_launched": ["Falcon 9"],
    "details":
      "SpaceX primary Falcon 9 launch pad, where all east coast Falcon 9s launched prior to the AMOS-6 anomaly. Initially used to launch Titan rockets for Lockheed Martin. Back online since CRS-13 on 2017-12-15."
  }
}
您可能需要的是一个几何图形类型为点的
功能
,如下所示:

{
  "id": "ccafs_slc_40",
  "full_name": "Cape Canaveral Air Force Station Space Launch Complex 40",
  "status": "active",
  "location": {
    "name": "Cape Canaveral",
    "region": "Florida",
    "latitude": 28.5618571,
    "longitude": -80.577366
  },
  "vehicles_launched": [
    "Falcon 9"
  ],
  "details": "SpaceX primary Falcon 9 launch pad, where all east coast Falcon 9s launched prior to the AMOS-6 anomaly. Initially used to launch Titan rockets for Lockheed Martin. Back online since CRS-13 on 2017-12-15."
}
{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [-80.577366, 28.5618571]
  },
  "properties": {
    "id": "ccafs_slc_40",
    "full_name": "Cape Canaveral Air Force Station Space Launch Complex 40",
    "status": "active",
    "location": {
      "name": "Cape Canaveral",
      "region": "Florida"
    },
    "vehicles_launched": ["Falcon 9"],
    "details":
      "SpaceX primary Falcon 9 launch pad, where all east coast Falcon 9s launched prior to the AMOS-6 anomaly. Initially used to launch Titan rockets for Lockheed Martin. Back online since CRS-13 on 2017-12-15."
  }
}
转换原始数组的每条记录后,需要将它们包装在
FeatureCollection
中,以便mapbox gl渲染:

{
  "type": "FeatureCollection",
  "features": [
    //...
  ]
}