Opened 4 years ago

Last modified 2 years ago

#4798 new enhancement

ST_AsGeoJSON should warn about duplicate keys

Reported by: tobwen Owned by: pramsey
Priority: low Milestone: PostGIS Fund Me
Component: postgis Version: master
Keywords: geojson, json, jsonb Cc:

Description

description

Although all JSON specifications (RFC 8259, RFC 7159, RFC 4627, and ECMA-404) allow multiple columns with the same name, PostgreSQL's JSONB does not. JSONB just takes the last occurance.

Most validators warn about duplicate columns, maybe PostGIS should warn about this, too? It might result in expected behaviour when storing as JSONB.

example

SELECT
    ST_AsGeoJSON(data.*)
FROM
    (SELECT
        1 AS column,
        2 AS column,
        ST_Transform(geom, 3035) geom
    FROM
        ST_SetSRID(ST_MakePoint(7, 51), 4326) geom
    ) data;

result JSON

{
  "type":"Feature",
  "geometry":{
    "type":"Point",
    "crs":{
      "type":"name",
      "properties":{
        "name":"EPSG:3035"
      }
    },
    "coordinates":[
      4110471.051819585,
      3103060.820290524
    ]
  },
  "properties":{
    "column":1,
    "column":2
  }
}

result JSONB

{
  "type":"Feature",
  "geometry":{
    "crs":{
      "type":"name",
      "properties":{
        "name":"EPSG:3035"
      }
    },
    "type":"Point",
    "coordinates":[
      4110471.051819585,
      3103060.820290524
    ]
  },
  "properties":{
    "column":2
  }
}

Change History (3)

comment:1 by pramsey, 4 years ago

Milestone: PostGIS 3.1.0PostGIS 3.2.0
Priority: mediumlow

comment:2 by pramsey, 3 years ago

Milestone: PostGIS 3.2.0PostGIS 3.3.0

comment:3 by robe, 2 years ago

Milestone: PostGIS 3.3.0PostGIS Fund Me
Note: See TracTickets for help on using tickets.