Skip to content

Commit 7441ac6

Browse files
authored
JSON Beautifier Widget (#2370)
* Create README.md * Add files via upload * Update README.md * Update README.md * Create HTML.html * Create Client_side.js
1 parent 6a6d963 commit 7441ac6

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
api.controller=function($scope) {
2+
/* widget controller */
3+
$scope.rawJson = '';
4+
$scope.formattedJson = '';
5+
$scope.error = '';
6+
7+
$scope.beautifyJSON = function(){
8+
try{
9+
$scope.error = '';
10+
const parsed = JSON.parse($scope.rawJson);
11+
$scope.formattedJson = JSON.stringify(parsed,null,2);
12+
}catch(e){
13+
$scope.error = 'Invalid JSON' + e.message;
14+
$scope.formattedJson = '';
15+
}
16+
};
17+
18+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<div class="container p-3">
2+
<h3>JSON Beautifier</h3>
3+
<div class="form-group mt-3">
4+
<label>Paste JSON Here</label>
5+
<textarea class="form-control" rows="8" ng-model="rawJson" placeholder='{"key":"value"}'></textarea>
6+
</div>
7+
<div class="mt-2">
8+
<button class="btn btn-primary btn-sm mr-1" ng-click="beautifyJSON()">
9+
Beautify
10+
</button>
11+
</div>
12+
<div class="mt-3" ng-if="error">
13+
<div class="alert alert-danger">
14+
{{error}}
15+
</div>
16+
</div>
17+
<div class="mt-3" ng-if="formattedJson">
18+
<label>Formatted JSON:</label>
19+
<pre class="bg-light p-3" style="overflow-x:auto">{{formattedJson}}</pre>
20+
</div>
21+
</div>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## JSON Beautifier Widget
2+
3+
The JSON Beautifier widget is a developer-focused tool designed to make working with JSON in ServiceNow fast, easy and efficient. It helps admins, developers and testers handles JSON payloads from APIs, Integration etc.
4+
5+
## Benefits
6+
- Reduces time spent manually formatting or checking JSON.
7+
- Helps identify error or differences between JSOn payload quickly
8+
9+
## Output
10+
![A test image](demo.png)
11+
31.9 KB
Loading

0 commit comments

Comments
 (0)