@@ -20,7 +20,7 @@ <h2>JSON Formatter</h2>
2020 < div class ="row my-4 ">
2121 <!-- Left Panel -->
2222 < div class ="col-md-4 ">
23- < textarea class ="form-control " rows ="15 " placeholder ="JSON input... "> </ textarea >
23+ < textarea class ="form-control " rows ="15 " placeholder ="JSON input... " id =" json_input " > </ textarea >
2424 </ div >
2525
2626 <!-- Center Panel (Upload & Validate Section) -->
@@ -35,7 +35,7 @@ <h2>JSON Formatter</h2>
3535 < option > 8 Tab Space</ option >
3636 </ select >
3737 </ div >
38- < button class ="btn btn-success mb-3 "> Format / Beautify</ button >
38+ < button class ="btn btn-success mb-3 " onclick =" formatJson() " > Format / Beautify</ button >
3939 < div class ="mt-4 ">
4040 < img src ="https://via.placeholder.com/300x250 " alt ="Ad " class ="img-fluid ">
4141 </ div >
@@ -44,7 +44,7 @@ <h2>JSON Formatter</h2>
4444
4545 <!-- Right Panel -->
4646 < div class ="col-md-4 ">
47- < textarea class =" form-control " rows =" 15 " placeholder =" Formatted JSON... " > </ textarea >
47+ < pre id =" formatted_JsonOutput " > </ pre >
4848 </ div >
4949 </ div >
5050
@@ -58,6 +58,20 @@ <h2>JSON Formatter</h2>
5858
5959<!-- Bootstrap JS -->
6060< script src ="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js "> </ script >
61+ < script >
62+ function format_json ( ) {
63+ const jsonInput = document . getElementById ( 'json_input' ) . value ;
64+ try {
65+ // Parse the input JSON
66+ const parsedJson = JSON . parse ( jsonInput ) ;
67+ // Format JSON with pretty print
68+ const formattedJson = JSON . stringify ( parsedJson , null , 4 ) ;
69+ document . getElementById ( 'formatted_JsonOutput' ) . textContent = formattedJson ;
70+ } catch ( error ) {
71+ document . getElementById ( 'formatted_JsonOutput' ) . textContent = 'Invalid JSON: ' + error . message ;
72+ }
73+ }
74+ </ script >
6175</ body >
6276</ html >
6377
0 commit comments