Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I validate & beautify JSON through a jquery/javascript plugin

I have a requirement where in I get JSON data from backend and I have to show that in textarea.currently, the data comes but its not formatted and validated.Now

1)How can I beautify JSON in the textarea ? 2)How can I validate it before saving ?

I have searched for all javascript/jquery plugins but I am not getting what I want.I want something like jslint

Thanks in advance

like image 852
Ravikiran Bhat Avatar asked Apr 04 '16 13:04

Ravikiran Bhat


People also ask

How do you emotionally validate someone?

How can you give emotional validation? Listen to, acknowledge, and rephrase what the person is saying. The point is to help them feel seen and heard, not to change or minimize their emotions.

What does it mean to validate someone?

July 10, 2022. Validation means that we are acknowledging another person's emotions, thoughts, experiences, values, and beliefs. Validation isn't about agreeing, placating, “fixing” the other person, trying to get someone to change, or repeating back what the other person has said.


1 Answers

Use JSON.stringify(object, 0, 4) with space parameter for a formatted JSON string.

var object = [{ "stop_id": 70021, "stop_name": "CALTRAIN - 22ND ST STATION", "stop_lat": 37.757692, "stop_lon": -122.392318, "zone_id": 3329 }, { "stop_id": 70022, "stop_name": "CALTRAIN - 22ND ST STATION", "stop_lat": 37.757692, "stop_lon": -122.392318, "zone_id": 3329 }, { "stop_id": 70151, "stop_name": "CALTRAIN - ATHERTON STATION", "stop_lat": 37.464458, "stop_lon": -122.198152, "zone_id": 3331 }];
document.write('<pre>' + JSON.stringify(object, 0, 4) + '</pre>');
like image 67
Nina Scholz Avatar answered Sep 26 '22 13:09

Nina Scholz