Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

Add format body option

Samir L. Boulema98cb9b32340f
diff --git a/lang/en-US.json b/lang/en-US.json
index fa4719a67..70ab9151f 100644
--- a/lang/en-US.json
+++ b/lang/en-US.json
@@ -184,6 +184,8 @@
"waiting_receive_schema": "(waiting to receive schema)",
"gql_prettify_invalid_query": "Couldn't prettify an invalid query, solve query syntax errors and try again",
"prettify_query": "Prettify Query",
+ "json_prettify_invalid_body": "Couldn't prettify an invalid body, solve json syntax errors and try again",
+ "prettify_body": "Prettify body",
"cancel": "Cancel",
"save": "Save",
"dismiss": "Dismiss",
diff --git a/pages/index.vue b/pages/index.vue
index e07093356..6bc86c36a 100644
--- a/pages/index.vue
+++ b/pages/index.vue
@@ -262,6 +262,13 @@
</button>
</label>
<input ref="payload" name="payload" type="file" @change="uploadPayload" />
+ <button
+ class="icon"
+ @click="prettifyRequestBody()"
+ v-tooltip="$t('prettify_body')"
+ >
+ <i class="material-icons">assistant</i>
+ </button>
</div>
</div>
</li>
@@ -2332,6 +2339,16 @@ export default {
},
})
},
+ prettifyRequestBody() {
+ try {
+ const jsonObj = JSON.parse(this.rawParams)
+ this.rawParams = JSON.stringify(jsonObj, null, 2)
+ } catch (e) {
+ this.$toast.error(`${this.$t("json_prettify_invalid_body")}`, {
+ icon: "error",
+ })
+ }
+ },
copyRequest() {
if (navigator.share) {
const time = new Date().toLocaleTimeString()