On this page
![AI-generated illustration; not taken on location · Comparison of GeoJSON position order [lon, lat] with the common latitude-first display order, marked swap = bug.](https://www.simplehabits.cloud/wp-content/uploads/2026/11/b2_check-longitude-and-latitude-order-in-ge.png)
Read Each Position in Longitude–Latitude Order
GeoJSON positions put longitude first and latitude second. To check a suspicious position, identify those two elements, inspect the document’s syntax and coordinate structure, and compare the interpreted position with documented location evidence. Exchange the first two elements only when that evidence establishes the intended pair.
A range warning can uncover a possible reversal, but it cannot establish what the producer meant — some pairs stay plausible in either order. A documented landmark, an expected geographic area, or an explicit reference position supplies the missing context.
The examples below are synthetic. Where an example includes a third value, its fixture explicitly defines that value as altitude; the cover illustration’s “optional altitude” label belongs to the same synthetic assumption. Treat that meaning as an assumption of these examples, and verify the meaning of additional values in real input against the producer’s documentation.
Begin with the position itself. GeoJSON places longitude before latitude, and its horizontal coordinates use decimal degrees. Label the elements explicitly so a reviewer can see which value is being checked against which expectation:
| Array element | Read it as | Inspection question |
|---|---|---|
| Index 0, the first element | Longitude | Does this match the documented longitude? |
| Index 1, the second element | Latitude | Does this match the documented latitude? |
For the synthetic position [120,45], the longitude candidate is 120 and the latitude candidate is 45 — labels that describe how to interpret the input, not proof that it names the intended place. GeoJSON uses World Geodetic System 1984 as its geographic coordinate reference system; record that context alongside the coordinate order when comparing an input with a reference, and check that the reference is suitable for the comparison before treating a numerical match as confirmation.
For three-element fixtures, assume the fixture documentation defines the value at index 2 as altitude, so [120,45,30] contains longitude 120, latitude 45 and altitude 30. The horizontal inspection concerns the first two elements; the third stays separate. For real input, ask what the producer documents about any additional value — meaning and units — because the decimal-degree convention for horizontal coordinates answers neither question. Also check the handoff between systems: what order does the producer document, and what order does the consuming interface expect? Write down both answers; they explain how a mismatch arose and where a confirmed correction belongs.
Separate Valid JSON from Correct Coordinates
Treat inspection as several checks with distinct outcomes. Successful JSON parsing establishes that the input passes the parser’s syntax check — nothing more. It does not establish the expected GeoJSON structure, that positions describe the intended place, or that a proposed exchange is justified:
| Check | Question it answers | What remains to investigate |
|---|---|---|
| JSON syntax | Can the input be parsed? | Coordinate structure and meaning |
| GeoJSON structure | Does the geometry follow the applicable structure rules? | Geographic plausibility and intent |
| Coordinate ranges | Do the horizontal values satisfy documented limits? | Whether they describe the intended location |
| Location comparison | Does the interpreted position agree with reliable context? | Whether a specific correction is justified |
These synthetic excerpts both use valid JSON syntax:
{"coordinates":[120,45]}
{"coordinates":[45,120]}
JSON.parse('{"coordinates":[45,120]}'); // parses fine — syntax has no opinion
// structure, range, and location checks are all still open
Parsing them does not choose between their positions. They are excerpts, so inspect the surrounding geometry before evaluating either as part of a complete document. Formatting makes the later checks easier — expand the surrounding object and nested arrays so you can see where a suspected position belongs, keep the original input available for comparison, and use formatting to improve readability without deliberately changing values.
Keep diagnostic language specific. JSON parsed successfully reports a syntax result; location confirmed requires evidence about the intended place. If the syntax check passes while the location remains unresolved, report both outcomes — that gives the next reviewer a clear starting point without implying every check has passed.
Use Ranges to Investigate Likely Reversals
Obtain the accepted longitude and latitude ranges from the specification or validation contract your project uses. Record the actual constraint, the value checked, and the array element that supplied it — a useful warning explains the failed check rather than merely calling the position invalid.
For this synthetic comparison, assume the configured checks accept longitude 120 and latitude 45, but reject latitude 120:
| Position | Longitude candidate | Latitude candidate | Result under the example’s checks |
|---|---|---|---|
[120,45] |
120 | 45 | Both candidates pass |
[45,120] |
45 | 120 | The latitude candidate fails |
Under those assumptions, the second pair suggests a possible reversal: exchanging its first two elements produces [120,45], which passes the configured checks. That result supplies a candidate for investigation — it does not establish intent. Possible explanations worth investigating include an incorrect value, an unexpected producer convention, or coordinates associated with the wrong record. Check the evidence before choosing among them.
An expected diagnostic for this fixture could read:
Input: [45,120]
Finding: latitude candidate 120 failed the configured range check
Candidate for investigation: [120,45]
Decision: retain the input pending location evidence
// the range check, made explicit:
const inRange = (lon, lat) => lon >= -180 && lon <= 180 && lat >= -90 && lat <= 90;
const [a, b] = [45, 120];
inRange(a, b); // false — latitude candidate 120 fails
inRange(b, a); // true — swapped candidate passes: a lead, not a verdict
The expected output is a warning with a proposed candidate — no correction has been confirmed. Next, compare that candidate with the producer's documentation and the expected location. If those checks disagree, retain the discrepancy for review: a range result answers whether the values pass particular constraints, and location evidence must establish whether the candidate describes the intended record.
Resolve Pairs That Fit Either Order
Compare the synthetic positions [12,48] and [48,12], assuming the project's documented range checks accept both candidates. A range-only result then leaves the intended position unresolved:
| Candidate | Longitude-first reading | Range result in this example |
|---|---|---|
[12,48] |
Longitude 12, latitude 48 | Accepted |
[48,12] |
Longitude 48, latitude 12 | Accepted |
The missing evidence concerns the location. Look for a documented landmark associated with the record, a reliable reference position, or an expected geographic area — and confirm how that reference labels longitude and latitude before comparing its values with the input, because references disagree about order too.
// both orders pass ranges — the tie needs context, not arithmetic:
const candidates = [[12,48],[48,12]];
candidates.every(([lon,lat]) => inRange(lon,lat)); // true — unresolved
For a landmark, verify that the reference describes the same feature as the record under review. For an expected area, ask whether it actually distinguishes the two candidates — a bounding box that contains both readings decides nothing. If the available context leaves both plausible, keep the result unresolved.
A synthetic test fixture can define its expected position directly:
{
"expected_longitude": 12,
"expected_latitude": 48
}
Against this fixture, [12,48] matches the expectation and [48,12] does not — the fields supply the intended answer for the exercise. A real record needs corresponding evidence from its own documentation or reference context. Record why the evidence is decisive: a useful review note identifies the reference position or expected area, states how its coordinate order was interpreted, and explains which candidate agrees with it. Avoid selecting whichever candidate looks more familiar; if no documented evidence distinguishes them, report both candidates pass the range checks; intent unresolved — that sentence tells the next reviewer exactly what information is still needed.
Find the Affected Position Inside the Geometry
Before changing values, identify the exact position within the document. Check the applicable geometry structure, then follow its nesting to each position: direct for an individual geometry, path-retained for nested geometries. Do not classify an array as a position solely because it contains two or three numbers — establish its role from the surrounding structure and the applicable geometry rules, and obtain those rules before designing any automatic traversal or rewrite.
These paths illustrate reporting across separate synthetic inputs; each array's role is explicitly established by its fixture, and the three-element fixture uses the altitude assumption introduced earlier:
| Path | Value | Review action |
|---|---|---|
geometry.coordinates |
[12,48] |
Compare this position with location evidence |
geometry.coordinates[0][1] |
[45,120,30] |
Investigate this nested position; retain its third value |
properties.display_values |
[45,120] |
Leave this fixture's unrelated application array unchanged |
For a document containing several geometries, include enough of the container path to identify which geometry owns the position — a warning that says only "coordinates are reversed" gives a reviewer too little information for a controlled correction. A proposed diagnostic record captures the observation without modifying it:
{
"path": "geometry.coordinates[0][1]",
"observed_position": [45,120,30],
"longitude_candidate": 45,
"latitude_candidate": 120,
"status": "needs_review"
}
Those diagnostic field names are workflow examples; include the failed constraint or unresolved comparison in the accompanying explanation. After locating one suspicious position, inspect the other verified positions — determine which have independent evidence of a mismatch and which already agree with their documented expectations.
Make a Confirmed Correction and Inspect the Result
Make a correction when the intended location is established. For this synthetic fixture, suppose its reference explicitly identifies longitude 120 and latitude 45, while the observed position is [45,120,30], with the fixture defining its third value as altitude. The confirmed change exchanges the first two elements and preserves the third:
| Item | Value |
|---|---|
| Original position | [45,120,30] |
| Documented horizontal expectation | Longitude 120, latitude 45 |
| Expected corrected position | [120,45,30] |
| Fixture-defined altitude, preserved | 30 |
original = [45, 120, 30]
corrected = [original[1], original[0], original[2]]
print(original)
print(corrected)
Expected output:
[45, 120, 30]
[120, 45, 30]
The example assumes the array's role and intended horizontal position have already been confirmed. For a two-element fixture, the explicit pair would be [45,120] and [120,45] — no third value to preserve. Apply the reviewed change at the identified coordinate path, preserve the surrounding structure and unrelated arrays, then compare the resulting document with the original to inspect the actual differences:
// diff the change, nothing else:
const before = JSON.stringify(doc.geometry.coordinates[0][1]);
doc.geometry.coordinates[0][1] = [120,45,30];
const after = JSON.stringify(doc.geometry.coordinates[0][1]);
// one changed path, one reviewed reason — the record writes itself
Keep Outcomes Distinguishable
Use separate results for different levels of evidence — collapsing them into a single "fixed" verdict is how unconfirmed swaps enter production:
| Result | Evidence | Expected action |
|---|---|---|
| Range warning | A horizontal value fails a documented constraint | Report the path and failed check; investigate intent |
| Unresolved intent | Both orders pass, or location evidence is insufficient | Retain the input and identify the missing context |
| Confirmed correction | Location evidence establishes the expected pair | Record the original position, corrected position and reason |
Inspect other positions before deciding whether they need the same exchange, and check for mixed ordering rather than assuming every position shares one mistake — one producer module with the wrong convention produces a document where most positions agree and a handful do not. Review each proposed change against the evidence available for it individually.
// scan for mixed ordering across a geometry:
const positions = flat(doc.geometry.coordinates);
const suspicious = positions.filter(([lon]) => Math.abs(lon) > 90);
// lon magnitudes over 90 are impossible longitudes — flag, don't auto-swap
Finally, repeat the relevant syntax, structure, range and location checks. Confirm that the corrected pair matches the documented expectation, that any additional value remains as intended, and that the recorded differences contain only the reviewed changes. The URL Workbench and JSON Inspector on this site both run locally: paste the geometry, expand the tree to the exact coordinate path, and the position-level comparison — original, candidate, evidence — stays on one screen from warning to confirmed correction.