@@ -20,7 +20,7 @@ <h2>JSON Formatter</h2>
20
20
< div class ="row my-4 ">
21
21
<!-- Left Panel -->
22
22
< 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 >
24
24
</ div >
25
25
26
26
<!-- Center Panel (Upload & Validate Section) -->
@@ -35,7 +35,7 @@ <h2>JSON Formatter</h2>
35
35
< option > 8 Tab Space</ option >
36
36
</ select >
37
37
</ 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 >
39
39
< div class ="mt-4 ">
40
40
< img src ="https://via.placeholder.com/300x250 " alt ="Ad " class ="img-fluid ">
41
41
</ div >
@@ -44,7 +44,7 @@ <h2>JSON Formatter</h2>
44
44
45
45
<!-- Right Panel -->
46
46
< div class ="col-md-4 ">
47
- < textarea class =" form-control " rows =" 15 " placeholder =" Formatted JSON... " > </ textarea >
47
+ < pre id =" formatted_JsonOutput " > </ pre >
48
48
</ div >
49
49
</ div >
50
50
@@ -58,6 +58,20 @@ <h2>JSON Formatter</h2>
58
58
59
59
<!-- Bootstrap JS -->
60
60
< script src ="
https://cdn.jsdelivr.net/npm/[email protected] /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 >
61
75
</ body >
62
76
</ html >
63
77
0 commit comments