Problems, need help? Have a tip or advice? Post it here.
5 posts Page 1 of 1
I have a data like:
(i) In case of fire, pull the Alarm Chain and stop the train immediately.
(ii) Try and put out the fire before it becomes a big blaze by using water or blankets, etc.
(iii) More people expire due to suffocation from smoke rather than due to actual burning.
(iv) Advise passengers to take a cloth, wet it in their drinking water and cover their nostrils.
(v) Instruct Passengers to go to the other end of the coach, which is away from the fire, and if possible cross over to the next coach through the vestibule.
(vi) Insist that passengers should save themselves first and not to bother about their luggage which can be retrieved later on.
(vii) Make sure that no passenger lies down on the floor.
(iii) After train has stopped, passengers should come down from the coach immediately.
(ix) Building up confidence of injured passengers by suitable advice is of great importance.


Now when i try to print it in json it prints everything in a single line. I was using textarea and that what the reason all comes in single line.

I then shifted to using richtext. But then JSON started to malform. I want the data to be displayed as above, one point below the other.

I am using DBF with richtext in front end. Due to multilines and para (<p>...</p>) tag being inserted, it does not form a valid JSON. How can the JSON be generated in Valid state?

Regards,
GenXCoders (Priya)
Image
where innovation meets technology
Richtext editor is very likely to add markup that will break JSON.
I'd suggest you switch back to textarea.

For formatting the output you may use <cms:nl2br /> (https://docs.couchcms.com/tags-reference/nl2br.html).

Hope this helps.
Richtext editor is very likely to add markup that will break JSON.
I'd suggest you switch back to textarea.

I did the reverting back to textarea as you suggested.

My <cms:template> block is defined as:
Code: Select all
<cms:template title="TO DO" clonable='1' routable='1' >
   <cms:editable type='uid' name='todo_uid' search_type='integer' order='1' />
   <cms:editable name='to_do_desc' label="To Do Description" type="textarea" no_xss_check='1' order='2' />
   <!-- Routes -->
   <cms:route name='list_todo' path='' />
    <cms:route name='create_todo' path='create' />
    <cms:route name='edit_todo' path='{:id}/edit' >
       <cms:route_validators id='non_zero_integer' />
   </cms:route>
   <cms:route name='view_todo' path='{:id}' />
   <cms:route name='delete_todo' path='{:id}/delete' >
       <cms:route_validators id='non_zero_integer' />
   </cms:route>
    <!-- Routes -->
</cms:template>


My JOSN is defined as:
Code: Select all
<?php require_once( '../couch/cms.php' ); ?>
<cms:template title='TO DO JSON' order='105' icon='home' hidden='1 '/>
<cms:content_type 'application/json'/>
{
   "todo":
   [   
      <cms:pages masterpage='to-do.php' show_future_entries='1'>
      {
         "todotitle":"<cms:show k_page_title />",
         "tododesc":"<cms:nl2br><cms:show to_do_desc /></cms:nl2br>"
      }
      <cms:if "<cms:not k_paginated_bottom />">, </cms:if>
      </cms:pages>
   ]
}
<?php COUCH::invoke(); ?>


The output JSON is:
{

"todo":

[

{

"todotitle":"Fire Fighting:",

"tododesc":"<p><strong>1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <u>Dry chemical powder type fire extinguisher (DCP)</u>:</strong></p><br />

<br />

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; These types are suitable for tackling petroleum, gas, electrical fire and controlling fires of textile fibres. Sodium based chemical powder is used on a fire which undergo chemical reaction.</p><br />

<br />

<p><strong>2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <u>How to Use</u>:</strong></p><br />

<br />

<p>(i)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Carry to the place of fire and keep it up right.</p><br />

<br />

<p>(ii)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Remove the safety clip. Hold the nozzle pipe tightly.</p><br />

<br />

<p>(iii)&nbsp;&nbsp;&nbsp;&nbsp; Strike the knob located in the cap.</p><br />

<br />

<p>(iv)&nbsp;&nbsp;&nbsp;&nbsp; Sealing disk of the cartridge gets broken and allows carbon dioxide gas to escape to the main shell and powder is pushed out.</p><br />

<br />

<p>(v)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Direct the steam of the powder at the base of the flame.</p><br />

<br />

<p>(vi)&nbsp;&nbsp;&nbsp;&nbsp; For effective result stand at about 1.5 to 2.5 metre near the seat of the fire.</p><br />

<br />

<p>(vii)&nbsp;&nbsp;&nbsp; Move forward with moving the nozzle rapidly from side to side in sweeping motion.</p><br />

<br />

<p>(viii)&nbsp;&nbsp;&nbsp; When using on outdoor fires operate from the up wind side for effective spray.</p><br />

<br />

<p>3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <u>Building Evacuation</u>:</p><br />

<br />

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; When the building fire alarm sounds:</p><br />

<br />

<p>(i)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Immediately evacuate using building emergency plan procedures.</p><br />

<br />

<p>(ii)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Walk to nearest exit/stairwell (close doors behind you)</p><br />

<br />

<p>(iii)&nbsp;&nbsp;&nbsp;&nbsp; Don&rsquo;t use elevators.</p><br />

<br />

<p>(iv)&nbsp;&nbsp;&nbsp;&nbsp; Proceed to the designated gathering area outside the building.</p><br />

<br />

<p>(v)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Do not re-enter building until cleared by authorised personnel.</p><br />

<br />

<p>(vi)&nbsp;&nbsp;&nbsp;&nbsp; Assist in evacuation of individuals with special needs.</p><br />

<br />

<p>&nbsp;</p><br />

<br />

<p><strong>4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <u>Suspicious substance in Railway premises</u>:</strong></p><br />

<br />

<p>(i)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Clear and isolate the contaminated area. Do not touch or disturb anything.</p><br />

<br />

<p>(ii)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Call police/fire service/bomb squad.</p><br />

<br />

<p>(iii)&nbsp;&nbsp;&nbsp;&nbsp; Wash your hands with soap and water.</p><br />

<br />

<p>(iv)&nbsp;&nbsp;&nbsp;&nbsp; Identify individuals who may have been exposed to the material.</p><br />

<br />

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (v)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Do not leave premises until disposed off by authorised personnel.</p><br />

<br />

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p><br />

<br />

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong> 5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <u>Bomb threat/Blast</u>:</strong></p><br />

<br />

<p>Person receiving call regarding bomb threat should:</p><br />

<br />

<p>(i)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Attempt to gain as much information as possible from the caller like type of device, time set, location, reason/purpose of the act, dialect mannerism and identity of the caller.</p><br />

<br />

<p>(ii)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Inform and alert the disaster management team (Bomb detection squad)</p><br />

<br />

<p>(iii)&nbsp;&nbsp;&nbsp;&nbsp; Alert police, fire brigade and explosive department.</p><br />

<br />

<p>(iv)&nbsp;&nbsp;&nbsp;&nbsp; Pass on the information to all departments concerned.</p><br />

<br />

<p>(v)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Take initiative for evacuation of all persons from premises.</p><br />

<br />

<p>(vi)&nbsp;&nbsp;&nbsp;&nbsp; Persons noticing a bomb like object, should bring it to the notice of the nearest available officer.</p><br />

<br />

<p>(vii)&nbsp;&nbsp;&nbsp; Inform GRP, RPF, and bomb detection squad.</p><br />

<br />

<p>(viii)&nbsp;&nbsp;&nbsp; Ensure all persons are away from the spot and avoid unnecessary crowding near the area.</p><br />

<br />

<p>(ix)&nbsp;&nbsp;&nbsp;&nbsp; Inform Control to take further steps for regulating train services.</p><br />

<br />

<p>(x)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Wait for clearance from the police department to restore normal working.</p><br />

<br />

<p>(xi)&nbsp;&nbsp;&nbsp;&nbsp; Utilise &ldquo;Caller ID&rdquo; facility, if provided, to trace the caller.</p><br />

<br />

<p>&nbsp;</p><br />

<br />

<p><strong>6.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <u>Radiation Emergency</u>:</strong></p><br />

<br />

<p>(a)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Personal injury involving radioactive material contamination:</p><br />

<br />

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (i)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Render first aid immediately for serious injuries, as trained.</p><br />

<br />

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (ii)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Call bomb squad, fire station.</p><br />

<br />

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (iii)&nbsp;&nbsp;&nbsp;&nbsp; If possible, without causing harm to the victim, monitor the injured; remove contaminated clothing and reduce personal contamination.</p><br />

<br />

<p>(b)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Radioactive contamination of personnel:</p><br />

<br />

<p>(i)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Remove and bag all contaminated clothing.</p><br />

<br />

<p>(ii)&nbsp; &nbsp;&nbsp;&nbsp; Call fire station, bomb squad, and police.</p><br />

<br />

<p>(iii) &nbsp;&nbsp;&nbsp; Skin contamination should be cleaned using mild soap and tepid water. Use portable survey meter to monitor for remaining contamination. If not free of contamination, re-wash and re-survey.</p><br />

<br />

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p><br />

<br />

<p><strong>7.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <u>What to do upon receipt of suspicious letter/package</u>:</strong></p><br />

<br />

<p>(i)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Handle with care.</p><br />

<br />

<p>(ii)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Don&rsquo;t shake or bump.</p><br />

<br />

<p>(iii)&nbsp;&nbsp;&nbsp;&nbsp; Isolate and look for indicators.</p><br />

<br />

<p>(iv)&nbsp;&nbsp;&nbsp;&nbsp; Don&rsquo;t open, smell or taste.</p><br />

<br />

<p>(v)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Treat it as suspect.</p><br />

<br />

<p>(vi)&nbsp;&nbsp;&nbsp;&nbsp; Call Police/Fire service/Bomb squad.</p><br />

<br />

<p>&nbsp;</p><br />

<br />

<p><strong>8.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <u>If parcel is Open and/or Threat is identified</u>:</strong></p><br />

<br />

<p>(a)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <u>For a bomb</u>:</p><br />

<br />

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (i)&nbsp; Evacuate immediately,</p><br />

<br />

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (ii)&nbsp; Call Police/ Fire service/Bomb squad.</p><br />

<br />

<p>(b)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <u>For Radiological</u>:</p><br />

<br />

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (i)&nbsp; Limit exposure- don&rsquo;t handle,</p><br />

<br />

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (ii)&nbsp; Evacuate area,</p><br />

<br />

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (iii) Shield yourself from the object.</p><br />

<br />

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (iv) Call Police/ Fire service/Bomb squad.</p><br />

<br />

<p>(c)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <u>For Biological or Chemical</u>:</p><br />

<br />

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (i)&nbsp; Isolate &ndash; don&rsquo;t handle,</p><br />

<br />

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (ii)&nbsp; Call Police/ Fire service/Bomb squad.</p><br />

<br />

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (iii)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Wash your hands with soap and water.</p>"

}

, {

"todotitle":"Test 2",

"tododesc":"TEst For Uid"

}

, {

"todotitle":"Disaster To Do Resource Material",

"tododesc":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin laoreet, dui quis pulvinar dapibus, elit lectus pellentesque mauris, id lacinia felis mi non velit. Nunc eu lobortis orci. Morbi at fringilla metus. Duis molestie, eros a vulputate pharetra, nulla diam bibendum urna, non gravida arcu magna ac eros. Vestibulum scelerisque tortor magna, et faucibus odio feugiat non. Vestibulum eu ligula ac elit aliquam posuere et vitae mauris. Donec aliquet finibus odio, vel viverra sem mollis ac.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin laoreet, dui quis pulvinar dapibus, elit lectus pellentesque mauris, id lacinia felis mi non velit. Nunc eu lobortis orci. Morbi at fringilla metus. Duis molestie, eros a vulputate pharetra, nulla diam bibendum urna, non gravida arcu magna ac eros. Vestibulum scelerisque tortor magna, et faucibus odio feugiat non. Vestibulum eu ligula ac elit aliquam posuere et vitae mauris. Donec aliquet finibus odio, vel viverra sem mollis ac. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin laoreet, dui quis pulvinar dapibus, elit lectus pellentesque mauris, id lacinia felis mi non velit. Nunc eu lobortis orci. Morbi at fringilla metus. Duis molestie, eros a vulputate pharetra, nulla diam bibendum urna, non gravida arcu magna ac eros. Vestibulum scelerisque tortor magna, et faucibus odio feugiat non. Vestibulum eu ligula ac elit aliquam posuere et vitae mauris. Donec aliquet finibus odio, vel viverra sem mollis ac."

}

]

}




JSON Error is:
SyntaxError: JSON.parse: bad control character in string literal at line 6 column 141 of the JSON data


jsonlint.com error is:
Error: Parse error on line 11:
...", "tododesc": "<p><strong>1.&nbsp;


Its a lot of text and points. This is required to supply to a mobile.

Regards,
GenXCoders (Priya)
Image
where innovation meets technology
All the <p> tags seem to be from the data persisted in the backend when you were using richtext.
Please delete that data and input it afresh as plain text (like the sample in your original post).

With that done, in your code where you are generating JSON, use <cms:escape_json> to properly escape the data (please see viewtopic.php?f=8&t=11400 for an example of its usage).
Code: Select all
{
     "todotitle":<cms:escape_json><cms:show k_page_title /></cms:escape_json>,
     "tododesc":<cms:escape_json><cms:nl2br><cms:show to_do_desc /></cms:nl2br></cms:escape_json>
}

This should now yield valid JSON.
@KK Sir,
Problem solved.

Did not know about the <cms:escape_json> tag of CouchCMS.
So what I could understand is that this tag basically adds escape sequences while generating the json output and hence sanitizes the data to fit json definition.

Regards,
GenXCoders (Priya)
Image
where innovation meets technology
5 posts Page 1 of 1

Who is online

In total there are 6 users online :: 1 registered, 0 hidden and 5 guests
(based on users active over the past 5 minutes)

Users browsing this forum: trendoman and 5 guests