Skip to content

US based ZIP code leading zero is truncated #2

Open

Description

@chewymole

Hi,
Very nice utility. Thank you for your contribution!
I only have 1 issue with it and that is zip codes that have leading zeros get truncated.

Is there a work around for this?
Example:

<cfset my_data.address = "1 n main st.">

<cfset my_data.city = "Looserville">

<cfset my_data.state = "bordom">

<cfset my_data.zip = "01234">

<cfdump var="#jsonutil.serializeToJson(my_data)#">

Thanks again
Chewy

Activity

  1. atuttle commented on Apr 15, 2016

    @atuttle
    Contributor

    I don't know that we can fix this, because in (all?) other cases, if a value is a numeric string we should show it as a numeric, e.g. phone: "5551235555" would become "phone": 5551235555... zip codes are a difficult problem because of the leading zeros.

    Additionally, international zip ("postal") codes often contain non-numeric data; so personally I tend to think of zip codes as strings 100% of the time.

    For that reason, I usually prepend a space or other alpha character to the zip code and then strip it out in the client.

  2. JamoCA commented on Jan 15, 2020

    @JamoCA

    I've been using zip-codes w/JSONUtil. To preserve values as strings, use Javacast("string", value). This will ensure that the value isn't treated generically as numeric and/or converted to scientific notation. When serializing or deserializing, ensure that strictMapping=true. (I used this method when submitting east coast zip codes to a USPS API endpoint.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions