Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7678259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:36:16+00:00 2026-05-31T17:36:16+00:00

My JSON contains special characters like: new line, double quotes etc. I am creating

  • 0

My JSON contains special characters like: new line, double quotes etc.

I am creating the JSON using Coldfusion server side script. But in case of special chars I get error due to wrongly formatted JSON. What should I do in such a case?

<cfoutput>
[
    <cfset loopIndex=0>
    <cfloop query="qEvents">

        <cfif loopIndex NEQ 0>,</cfif>

        <cfif is_allday EQ 1>
            <cfset isallDayEvent = "true">
        <cfelse>
            <cfset isallDayEvent = "false">
        </cfif>

        {
            "title": "#title#",
            "start": "#DateFormat(start_date_time,'mm/dd/yyyy')# #TimeFormat(start_date_time,'hh:mm tt')#",
            "end": "#DateFormat(end_date_time,'mm/dd/yyyy')# #TimeFormat(end_date_time,'hh:mm tt')#",
            "allDay": #isallDayEvent#,
            "eventID": "#event_id#",
            "duration": "#duration#",
            "note": "#note#",
            "location": "#location#"
        }
        <cfset loopIndex=loopIndex+1>
    </cfloop>
]
</cfoutput>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:36:17+00:00Added an answer on May 31, 2026 at 5:36 pm

    Rather than writing the JSON by hand, you should generate an array of structs and then use serializeJSON() to convert it to a valid JSON string:

    <cfset thisArrayBecomesJSON = [] />
    
    <cfloop query="qEvents">
    
        <cfif is_allday EQ 1>
            <cfset isAllDayEvent = "true" />
        <cfelse>
            <cfset isAllDayEvent = "false" />
        </cfif>
    
        <cfset thisEvent = {
            'title' = title,
            'start' = dateFormat( start_date_time, 'mm/dd/yyyy' ) & timeFormat( start_date_time, 'hh:mm tt' ),
            'end' = dateFormat( end_date_time, 'mm/dd/yyyy' ) & timeFormat( end_date_time, 'hh:mm tt' ),
            'allDay' = isAllDayEvent,
            'eventID' = event_id,
            'duration' = duration,
            'note' = note,
            'location' = location
        } />
    
        <cfset arrayAppend( thisArrayBecomesJSON, thisEvent ) />
    
    </cfloop>
    
    <cfset myJSON = serializeJSON( thisArrayBecomesJSON ) />
    
    <cfoutput>#myJSON#</cfoutput>
    

    This is untested, but I think it should work ok – there may be some syntax errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSON result that contains numerous records. I'd like to show the
I'm reading JSON data with PHP and that data contains empty objects (like {}
I'd like to validate json contains a list of key/values before attempting to marshall
I'm trying to parse an NSString that contains JSON data into an NSDictionary using
Can someone pleas explain to me why json which contains a string with double
I have a string in PHP that contains both single and double quotes. I
Working with JSON is quite new to me, yet I already like it. But
My JSON response contains characters in decimal format such as My Friend&#39;s Story instead
I have a JSON that contains the following: {p1:{debris:{titanium:0,silicum:0}},p2:{debris:{titanium:0,silicum:0}}... I declare the data using
I have a two dimensional JSON array where each element contains several attributes. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.