ST_AsText vs ST_AsGeoJSON: Which PostGIS Export Should You Use?

ST_AsText and ST_AsGeoJSON serialize the same PostGIS geometry for different workflows. WKT is compact and convenient for SQL consoles; GeoJSON fits naturally into JavaScript, HTTP APIs and web maps.

Choose ST_AsText for inspection and copy/paste

SELECT id, ST_AsText(ST_Transform(geom, 4326)) AS wkt
FROM parcels
WHERE id = 42;

WKT is ideal when a developer wants to eyeball a geometry or paste it into a map viewer. It describes geometry only, so attach attributes separately.

Choose ST_AsGeoJSON for apps and APIs

SELECT jsonb_build_object(
  'type', 'Feature',
  'geometry', ST_AsGeoJSON(ST_Transform(geom, 4326))::jsonb,
  'properties', to_jsonb(p) - 'geom'
) FROM parcels AS p;

GeoJSON can carry a complete Feature with properties and is immediately consumable by mapping libraries. Open a result in the GeoJSON viewer, or use WKT Studio's REST API when the workflow needs persistent projects.

Both outputs can lose metadata if you serialize only the geometry. Decide explicitly whether your consumer needs just coordinates or a full Feature with attributes.

Practical decision

Use ST_AsText for debugging, tickets and human review. Use ST_AsGeoJSON for web clients and APIs. In both cases, transform to 4326 when the destination is a conventional web map and verify longitude/latitude order.

Keep reading