Skip to content

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

feat(common): use jq for JSON response filtering (#5703)

Gerard Balaorobdc2d33f5037
diff --git a/packages/hoppscotch-common/locales/af.json b/packages/hoppscotch-common/locales/af.json
index 4852f0a06..7f1bae15b 100644
--- a/packages/hoppscotch-common/locales/af.json
+++ b/packages/hoppscotch-common/locales/af.json
@@ -623,7 +623,7 @@
"response": {
"audio": "Audio",
"body": "Reaksie liggaam",
- "filter_response_body": "Filter JSON response body (uses JSONPath syntax)",
+ "filter_response_body": "Filter JSON response body (uses jq syntax)",
"headers": "Opskrifte",
"html": "HTML",
"image": "Beeld",
diff --git a/packages/hoppscotch-common/locales/ar.json b/packages/hoppscotch-common/locales/ar.json
index 08a9b9496..3723ec944 100644
--- a/packages/hoppscotch-common/locales/ar.json
+++ b/packages/hoppscotch-common/locales/ar.json
@@ -623,7 +623,7 @@
"response": {
"audio": "صوت",
"body": "Body",
- "filter_response_body": "Filter JSON response body (uses JSONPath syntax)",
+ "filter_response_body": "Filter JSON response body (uses jq syntax)",
"headers": "Headers",
"html": "HTML",
"image": "صورة",
diff --git a/packages/hoppscotch-common/locales/ca.json b/packages/hoppscotch-common/locales/ca.json
index e4376a344..35d122643 100644
--- a/packages/hoppscotch-common/locales/ca.json
+++ b/packages/hoppscotch-common/locales/ca.json
@@ -623,7 +623,7 @@
"response": {
"audio": "Audio",
"body": "Cos de resposta",
- "filter_response_body": "Filtrar el cos de la resposta JSON (utilitza la sintaxi JSONPath)",
+ "filter_response_body": "Filtrar el cos de la resposta JSON (utilitza la sintaxi jq)",
"headers": "Capçaleres",
"html": "HTML",
"image": "Imatge",
diff --git a/packages/hoppscotch-common/locales/cn.json b/packages/hoppscotch-common/locales/cn.json
index 2a37a8a46..0cea8453d 100644
--- a/packages/hoppscotch-common/locales/cn.json
+++ b/packages/hoppscotch-common/locales/cn.json
@@ -1182,7 +1182,7 @@
"body": "响应体",
"duplicated": "响应重名",
"duplicate_name_error": "有同名的响应已存在",
- "filter_response_body": "筛选JSON响应本体(使用JSONPath语法)",
+ "filter_response_body": "筛选JSON响应本体(使用jq语法)",
"headers": "响应头",
"request_headers": "请求头",
"html": "HTML",
diff --git a/packages/hoppscotch-common/locales/cs.json b/packages/hoppscotch-common/locales/cs.json
index 58b21ba74..2ce89f222 100644
--- a/packages/hoppscotch-common/locales/cs.json
+++ b/packages/hoppscotch-common/locales/cs.json
@@ -625,7 +625,7 @@
"response": {
"audio": "Audio",
"body": "Tělo odpovědi",
- "filter_response_body": "Filter JSON response body (uses JSONPath syntax)",
+ "filter_response_body": "Filter JSON response body (uses jq syntax)",
"headers": "Záhlaví",
"html": "HTML",
"image": "Obrázek",
diff --git a/packages/hoppscotch-common/locales/da.json b/packages/hoppscotch-common/locales/da.json
index 6803e02a4..ad6132b4b 100644
--- a/packages/hoppscotch-common/locales/da.json
+++ b/packages/hoppscotch-common/locales/da.json
@@ -620,7 +620,7 @@
"response": {
"audio": "Lyd",
"body": "Svarbesked",
- "filter_response_body": "Filtrer JSON-svarbesked (bruger JSONPath-syntaks)",
+ "filter_response_body": "Filtrer JSON-svarbesked (bruger jq-syntaks)",
"headers": "Headers",
"html": "HTML",
"image": "Billede",
diff --git a/packages/hoppscotch-common/locales/de.json b/packages/hoppscotch-common/locales/de.json
index c415e6eb1..e1f5dcc24 100644
--- a/packages/hoppscotch-common/locales/de.json
+++ b/packages/hoppscotch-common/locales/de.json
@@ -727,7 +727,7 @@
"body": "Antworttext",
"duplicated": "Antwort dupliziert",
"duplicate_name_error": "Antwort mit demselben Namen existiert bereits",
- "filter_response_body": "JSON-Antwortkörper filtern (verwendet JSONPath-Syntax)",
+ "filter_response_body": "JSON-Antwortkörper filtern (verwendet jq-Syntax)",
"headers": "Header",
"html": "HTML",
"image": "Bild",
diff --git a/packages/hoppscotch-common/locales/el.json b/packages/hoppscotch-common/locales/el.json
index c13edb38e..de856010d 100644
--- a/packages/hoppscotch-common/locales/el.json
+++ b/packages/hoppscotch-common/locales/el.json
@@ -623,7 +623,7 @@
"response": {
"audio": "Audio",
"body": "Σώμα απόκρισης",
- "filter_response_body": "Filter JSON response body (uses JSONPath syntax)",
+ "filter_response_body": "Filter JSON response body (uses jq syntax)",
"headers": "Κεφαλίδες",
"html": "HTML",
"image": "Εικόνα",
diff --git a/packages/hoppscotch-common/locales/en.json b/packages/hoppscotch-common/locales/en.json
index 9dc71496f..6c2e91f3d 100644
--- a/packages/hoppscotch-common/locales/en.json
+++ b/packages/hoppscotch-common/locales/en.json
@@ -1202,7 +1202,7 @@
"body": "Response Body",
"duplicated": "Response duplicated",
"duplicate_name_error": "Same name response already exists",
- "filter_response_body": "Filter JSON response body (uses JSONPath syntax)",
+ "filter_response_body": "Filter JSON response body (uses jq syntax)",
"headers": "Headers",
"request_headers": "Request Headers",
"html": "HTML",
diff --git a/packages/hoppscotch-common/locales/es.json b/packages/hoppscotch-common/locales/es.json
index be9f6541c..18b38a6ba 100644
--- a/packages/hoppscotch-common/locales/es.json
+++ b/packages/hoppscotch-common/locales/es.json
@@ -623,7 +623,7 @@
"response": {
"audio": "Audio",
"body": "Cuerpo de respuesta",
- "filter_response_body": "Filtrar el cuerpo de la respuesta JSON (utiliza la sintaxis JSONPath)",
+ "filter_response_body": "Filtrar el cuerpo de la respuesta JSON (utiliza la sintaxis jq)",
"headers": "Encabezados",
"html": "HTML",
"image": "Imagen",
diff --git a/packages/hoppscotch-common/locales/fi.json b/packages/hoppscotch-common/locales/fi.json
index f2ced5917..604df9a7b 100644
--- a/packages/hoppscotch-common/locales/fi.json
+++ b/packages/hoppscotch-common/locales/fi.json
@@ -623,7 +623,7 @@
"response": {
"audio": "Audio",
"body": "Vastauselin",
- "filter_response_body": "Filter JSON response body (uses JSONPath syntax)",
+ "filter_response_body": "Filter JSON response body (uses jq syntax)",
"headers": "Otsikot",
"html": "HTML",
"image": "Kuva",
diff --git a/packages/hoppscotch-common/locales/fr.json b/packages/hoppscotch-common/locales/fr.json
index 327cae364..97b090487 100644
--- a/packages/hoppscotch-common/locales/fr.json
+++ b/packages/hoppscotch-common/locales/fr.json
@@ -930,7 +930,7 @@
"body": "Coprs de la réponse",
"duplicated": "Réponse dupliquée",
"duplicate_name_error": "Une réponse avec le même nom existe déjà",
- "filter_response_body": "Filtrer le corps de la réponse JSON (utilise la syntaxe JSONPath)",
+ "filter_response_body": "Filtrer le corps de la réponse JSON (utilise la syntaxe jq)",
"headers": "En-têtes",
"request_headers": "En-têtes de requête",
"html": "HTML",
diff --git a/packages/hoppscotch-common/locales/he.json b/packages/hoppscotch-common/locales/he.json
index 7202bc8ab..7b71d809f 100644
--- a/packages/hoppscotch-common/locales/he.json
+++ b/packages/hoppscotch-common/locales/he.json
@@ -623,7 +623,7 @@
"response": {
"audio": "Audio",
"body": "גוף תגובה",
- "filter_response_body": "Filter JSON response body (uses JSONPath syntax)",
+ "filter_response_body": "Filter JSON response body (uses jq syntax)",
"headers": "כותרות",
"html": "HTML",
"image": "תמונה",
diff --git a/packages/hoppscotch-common/locales/hu.json b/packages/hoppscotch-common/locales/hu.json
index 19c1839c3..c814f4efc 100644
--- a/packages/hoppscotch-common/locales/hu.json
+++ b/packages/hoppscotch-common/locales/hu.json
@@ -623,7 +623,7 @@
"response": {
"audio": "Hang",
"body": "Válasz törzse",
- "filter_response_body": "JSON-válasz törzsének szűrése (JSONPath szintaxist használ)",
+ "filter_response_body": "JSON-válasz törzsének szűrése (jq szintaxist használ)",
"headers": "Fejlécek",
"html": "HTML",
"image": "Kép",
diff --git a/packages/hoppscotch-common/locales/id.json b/packages/hoppscotch-common/locales/id.json
index 3d42b587d..0684c8621 100644
--- a/packages/hoppscotch-common/locales/id.json
+++ b/packages/hoppscotch-common/locales/id.json
@@ -623,7 +623,7 @@
"response": {
"audio": "Audio",
"body": "Response Body",
- "filter_response_body": "Filter body respons JSON (menggunakan sintaks JSONPath)",
+ "filter_response_body": "Filter body respons JSON (menggunakan sintaks jq)",
"headers": "Headers",
"html": "HTML",
"image": "Gambar",
diff --git a/packages/hoppscotch-common/locales/it.json b/packages/hoppscotch-common/locales/it.json
index ea6d5d492..d36b32d62 100644
--- a/packages/hoppscotch-common/locales/it.json
+++ b/packages/hoppscotch-common/locales/it.json
@@ -623,7 +623,7 @@
"response": {
"audio": "Audio",
"body": "Corpo della risposta",
- "filter_response_body": "Filter JSON response body (uses JSONPath syntax)",
+ "filter_response_body": "Filter JSON response body (uses jq syntax)",
"headers": "Intestazioni",
"html": "HTML",
"image": "Immagine",
diff --git a/packages/hoppscotch-common/locales/ja.json b/packages/hoppscotch-common/locales/ja.json
index 7dd3e6c03..3739238b0 100644
--- a/packages/hoppscotch-common/locales/ja.json
+++ b/packages/hoppscotch-common/locales/ja.json
@@ -623,7 +623,7 @@
"response": {
"audio": "Audio",
"body": "レスポンスボディ",
- "filter_response_body": "JSONレスポンスボディをフィルタ (JSONPathシンタックスを使用)",
+ "filter_response_body": "JSONレスポンスボディをフィルタ (jqシンタックスを使用)",
"headers": "ヘッダー",
"html": "HTML",
"image": "画像",
diff --git a/packages/hoppscotch-common/locales/ko.json b/packages/hoppscotch-common/locales/ko.json
index 04d3b3f79..8274dcfc3 100644
--- a/packages/hoppscotch-common/locales/ko.json
+++ b/packages/hoppscotch-common/locales/ko.json
@@ -623,7 +623,7 @@
"response": {
"audio": "Audio",
"body": "응답 본문",
- "filter_response_body": "Filter JSON response body (uses JSONPath syntax)",
+ "filter_response_body": "Filter JSON response body (uses jq syntax)",
"headers": "헤더",
"html": "HTML",
"image": "이미지",
diff --git a/packages/hoppscotch-common/locales/nl.json b/packages/hoppscotch-common/locales/nl.json
index da6578c15..58818794b 100644
--- a/packages/hoppscotch-common/locales/nl.json
+++ b/packages/hoppscotch-common/locales/nl.json
@@ -623,7 +623,7 @@
"response": {
"audio": "Audio",
"body": "Reactie inhoud",
- "filter_response_body": "Filter JSON response body (uses JSONPath syntax)",
+ "filter_response_body": "Filter JSON response body (uses jq syntax)",
"headers": "Headers",
"html": "HTML",
"image": "Afbeelding",
diff --git a/packages/hoppscotch-common/locales/no.json b/packages/hoppscotch-common/locales/no.json
index 33515d043..fdf678227 100644
--- a/packages/hoppscotch-common/locales/no.json
+++ b/packages/hoppscotch-common/locales/no.json
@@ -623,7 +623,7 @@
"response": {
"audio": "Audio",
"body": "Svarkropp",
- "filter_response_body": "Filter JSON response body (uses JSONPath syntax)",
+ "filter_response_body": "Filter JSON response body (uses jq syntax)",
"headers": "Overskrifter",
"html": "HTML",
"image": "Bilde",
diff --git a/packages/hoppscotch-common/locales/pl.json b/packages/hoppscotch-common/locales/pl.json
index 1b1b252f2..363f38a40 100644
--- a/packages/hoppscotch-common/locales/pl.json
+++ b/packages/hoppscotch-common/locales/pl.json
@@ -623,7 +623,7 @@
"response": {
"audio": "Audio",
"body": "Ciało odpowiedzi",
- "filter_response_body": "Filter JSON response body (uses JSONPath syntax)",
+ "filter_response_body": "Filter JSON response body (uses jq syntax)",
"headers": "Nagłówki",
"html": "HTML",
"image": "Obraz",
diff --git a/packages/hoppscotch-common/locales/pt-br.json b/packages/hoppscotch-common/locales/pt-br.json
index f5bd44999..6acc4693a 100644
--- a/packages/hoppscotch-common/locales/pt-br.json
+++ b/packages/hoppscotch-common/locales/pt-br.json
@@ -727,7 +727,7 @@
"body": "Corpo de Resposta",
"duplicated": "Resposta duplicada",
"duplicate_name_error": "Já existe uma resposta com o mesmo nome",
- "filter_response_body": "Filtar corpo de resposta JSON (utiliza sintaxe JSONPath)",
+ "filter_response_body": "Filtar corpo de resposta JSON (utiliza sintaxe jq)",
"headers": "Cabeçalhos",
"request_headers": "Cabeçalhos de Requisição",
"html": "HTML",
diff --git a/packages/hoppscotch-common/locales/pt.json b/packages/hoppscotch-common/locales/pt.json
index 63015710b..0847c960f 100644
--- a/packages/hoppscotch-common/locales/pt.json
+++ b/packages/hoppscotch-common/locales/pt.json
@@ -623,7 +623,7 @@
"response": {
"audio": "Audio",
"body": "Corpo de Resposta",
- "filter_response_body": "Filter JSON response body (uses JSONPath syntax)",
+ "filter_response_body": "Filter JSON response body (uses jq syntax)",
"headers": "Cabeçalhos",
"html": "HTML",
"image": "Imagem",
diff --git a/packages/hoppscotch-common/locales/ro.json b/packages/hoppscotch-common/locales/ro.json
index 9fdf52463..639dd324b 100644
--- a/packages/hoppscotch-common/locales/ro.json
+++ b/packages/hoppscotch-common/locales/ro.json
@@ -623,7 +623,7 @@
"response": {
"audio": "Audio",
"body": "Corpul de răspuns",
- "filter_response_body": "Filtrează corpul răspunsului JSON (folosește sintaxa JSONPath)",
+ "filter_response_body": "Filtrează corpul răspunsului JSON (folosește sintaxa jq)",
"headers": "Anteturi",
"html": "HTML",
"image": "Imagine",
diff --git a/packages/hoppscotch-common/locales/ru.json b/packages/hoppscotch-common/locales/ru.json
index e5c67fc07..df173dcc5 100644
--- a/packages/hoppscotch-common/locales/ru.json
+++ b/packages/hoppscotch-common/locales/ru.json
@@ -618,7 +618,7 @@
"response": {
"audio": "Аудио",
"body": "Тело ответа",
- "filter_response_body": "Отфильтровать ответ в формате JSON (используется синтаксис JSONPath)",
+ "filter_response_body": "Отфильтровать ответ в формате JSON (используется синтаксис jq)",
"headers": "Заголовки",
"html": "HTML",
"image": "Изображение",
diff --git a/packages/hoppscotch-common/locales/sr.json b/packages/hoppscotch-common/locales/sr.json
index f2e198ee3..3b29fcfd6 100644
--- a/packages/hoppscotch-common/locales/sr.json
+++ b/packages/hoppscotch-common/locales/sr.json
@@ -623,7 +623,7 @@
"response": {
"audio": "Audio",
"body": "Тело за одговор",
- "filter_response_body": "Filter JSON response body (uses JSONPath syntax)",
+ "filter_response_body": "Filter JSON response body (uses jq syntax)",
"headers": "Заглавља",
"html": "ХТМЛ",
"image": "Слика",
diff --git a/packages/hoppscotch-common/locales/sv.json b/packages/hoppscotch-common/locales/sv.json
index 0de8b4b8a..143e06a41 100644
--- a/packages/hoppscotch-common/locales/sv.json
+++ b/packages/hoppscotch-common/locales/sv.json
@@ -623,7 +623,7 @@
"response": {
"audio": "Audio",
"body": "Svarskommitté",
- "filter_response_body": "Filter JSON response body (uses JSONPath syntax)",
+ "filter_response_body": "Filter JSON response body (uses jq syntax)",
"headers": "Rubriker",
"html": "HTML",
"image": "Bild",
diff --git a/packages/hoppscotch-common/locales/tr.json b/packages/hoppscotch-common/locales/tr.json
index 89eb11ece..b24355e00 100644
--- a/packages/hoppscotch-common/locales/tr.json
+++ b/packages/hoppscotch-common/locales/tr.json
@@ -618,7 +618,7 @@
"response": {
"audio": "Ses",
"body": "Yanıt gövdesi",
- "filter_response_body": "JSON yanıt gövdesini filtrele (JSONPath sözdizimi kullanır)",
+ "filter_response_body": "JSON yanıt gövdesini filtrele (jq sözdizimi kullanır)",
"headers": "Başlıklar",
"html": "HTML",
"image": "Resim",
diff --git a/packages/hoppscotch-common/locales/tw.json b/packages/hoppscotch-common/locales/tw.json
index 12bc4ae14..b80a64501 100644
--- a/packages/hoppscotch-common/locales/tw.json
+++ b/packages/hoppscotch-common/locales/tw.json
@@ -639,7 +639,7 @@
"response": {
"audio": "音訊",
"body": "回應本體",
- "filter_response_body": "篩選 JSON 回應本體 (使用 JSONPath 語法)",
+ "filter_response_body": "篩選 JSON 回應本體 (使用 jq 語法)",
"headers": "回應標頭",
"html": "HTML",
"image": "影像",
diff --git a/packages/hoppscotch-common/locales/uk.json b/packages/hoppscotch-common/locales/uk.json
index 1d2277558..6f154ed37 100644
--- a/packages/hoppscotch-common/locales/uk.json
+++ b/packages/hoppscotch-common/locales/uk.json
@@ -623,7 +623,7 @@
"response": {
"audio": "Audio",
"body": "Орган реагування",
- "filter_response_body": "Фільтр тіла відповідей JSON (використовує синтаксис JSONPath)",
+ "filter_response_body": "Фільтр тіла відповідей JSON (використовує синтаксис jq)",
"headers": "Заголовки",
"html": "HTML",
"image": "Зображення",
diff --git a/packages/hoppscotch-common/locales/vi.json b/packages/hoppscotch-common/locales/vi.json
index 0bbab8f3c..2e65e257b 100644
--- a/packages/hoppscotch-common/locales/vi.json
+++ b/packages/hoppscotch-common/locales/vi.json
@@ -623,7 +623,7 @@
"response": {
"audio": "Âm thanh",
"body": "Nội dung Phản hồi",
- "filter_response_body": "Lọc nội dung phản hồi JSON (sử dụng cú pháp JSONPath)",
+ "filter_response_body": "Lọc nội dung phản hồi JSON (sử dụng cú pháp jq)",
"headers": "Headers",
"html": "HTML",
"image": "Hình ảnh",
diff --git a/packages/hoppscotch-common/package.json b/packages/hoppscotch-common/package.json
index 0490d9b70..d91ba8ce2 100644
--- a/packages/hoppscotch-common/package.json
+++ b/packages/hoppscotch-common/package.json
@@ -76,10 +76,10 @@
"highlightjs-curl": "1.3.0",
"insomnia-importers": "3.6.0",
"io-ts": "2.2.22",
+ "jq-wasm": "1.1.0-jq-1.8.1",
"js-md5": "0.8.3",
"js-yaml": "4.1.1",
"jsonc-parser": "3.3.1",
- "jsonpath-plus": "10.3.0",
"lodash-es": "4.17.22",
"lossless-json": "4.3.0",
"markdown-it": "14.1.0",
diff --git a/packages/hoppscotch-common/src/components/lenses/renderers/JSONLensRenderer.vue b/packages/hoppscotch-common/src/components/lenses/renderers/JSONLensRenderer.vue
index 08d3c92f8..20165bea6 100644
--- a/packages/hoppscotch-common/src/components/lenses/renderers/JSONLensRenderer.vue
+++ b/packages/hoppscotch-common/src/components/lenses/renderers/JSONLensRenderer.vue
@@ -118,23 +118,30 @@
</span>
<div
v-if="filterResponseError"
- class="flex items-center justify-center rounded px-2 py-1 text-tiny text-accentContrast"
+ v-tippy="{
+ theme: 'tooltip',
+ content: filterResponseError.error,
+ placement: 'bottom',
+ }"
+ role="alert"
+ aria-live="assertive"
+ class="flex max-w-[10rem] cursor-help items-center justify-center rounded px-2 py-1 text-tiny text-accentContrast sm:max-w-[16rem]"
:class="{
'bg-red-500':
filterResponseError.type === 'JSON_PARSE_FAILED' ||
- filterResponseError.type === 'JSON_PATH_QUERY_ERROR',
+ filterResponseError.type === 'JSON_QUERY_FAILED',
'bg-amber-500': filterResponseError.type === 'RESPONSE_EMPTY',
}"
>
- <icon-lucide-info class="svg-icons mr-1.5" />
- <span>{{ filterResponseError.error }}</span>
+ <icon-lucide-info class="svg-icons mr-1.5 flex-shrink-0" />
+ <span class="truncate">{{ filterResponseError.error }}</span>
</div>
<HoppButtonSecondary
v-if="showResponse"
v-tippy="{ theme: 'tooltip' }"
:title="t('app.wiki')"
:icon="IconHelpCircle"
- to="https://github.com/JSONPath-Plus/JSONPath"
+ to="https://jqlang.org/manual/"
blank
/>
</div>
@@ -265,7 +272,8 @@ import * as O from "fp-ts/Option"
import * as E from "fp-ts/Either"
import { pipe } from "fp-ts/function"
import { computed, ref, reactive } from "vue"
-import { JSONPath } from "jsonpath-plus"
+import { computedAsync, refDebounced } from "@vueuse/core"
+import * as jq from "jq-wasm"
import { useCodemirror } from "@composables/codemirror"
import { HoppRESTResponse } from "~/helpers/types/HoppRESTResponse"
import jsonParse, { JSONObjectMember, JSONValue } from "~/helpers/jsonParse"
@@ -326,10 +334,11 @@ const isHttpResponse = computed(() => {
const toggleFilter = ref(false)
const filterQueryText = ref("")
+const debouncedFilterQuery = refDebounced(filterQueryText, 300)
type BodyParseError =
| { type: "JSON_PARSE_FAILED" }
- | { type: "JSON_PATH_QUERY_FAILED"; error: Error }
+ | { type: "JSON_QUERY_FAILED"; error: Error }
const responseJsonObject = computed(() => {
if (isHttpResponse.value) {
@@ -362,28 +371,41 @@ const responseName = computed(() => {
const { responseBodyText } = useResponseBody(props.response)
-const jsonResponseBodyText = computed(() => {
- if (filterQueryText.value.length > 0 && responseJsonObject.value) {
- return pipe(
- responseJsonObject.value,
- E.chain((parsedJSON) =>
- E.tryCatch(
- () =>
- JSONPath({
- path: filterQueryText.value,
- json: JSON.parse(LJSON.stringify(parsedJSON as any) || "{}"),
- }),
- (err): BodyParseError => ({
- type: "JSON_PATH_QUERY_FAILED",
- error: err as Error,
- })
+const jsonResponseBodyText = computedAsync(
+ async (): Promise<E.Either<BodyParseError, string | object>> => {
+ if (debouncedFilterQuery.value.length > 0 && responseJsonObject.value) {
+ if (E.isLeft(responseJsonObject.value)) {
+ return responseJsonObject.value
+ }
+
+ try {
+ const input = JSON.parse(
+ LJSON.stringify(responseJsonObject.value.right as any) || "{}"
)
- ),
- E.map((result: any) => result as string | object)
- )
- }
- return E.right(responseBodyText.value)
-})
+ const { exitCode, stdout, stderr } = await jq.raw(
+ input,
+ debouncedFilterQuery.value
+ )
+
+ if (exitCode !== 0) {
+ // Extract first line of jq error for user-friendly message
+ const errorMessage = stderr?.split("\n")[0]?.trim() || "Syntax Error"
+ throw new Error(errorMessage)
+ }
+
+ return E.right(stdout as string | object)
+ } catch (err) {
+ return E.left({
+ type: "JSON_QUERY_FAILED",
+ error: err as Error,
+ })
+ }
+ }
+
+ return E.right(responseBodyText.value)
+ },
+ E.right(responseBodyText.value)
+)
const jsonBodyText = computed(() => {
const { responseBodyText } = useResponseBody(
@@ -395,7 +417,7 @@ const jsonBodyText = computed(() => {
E.getOrElse(() => responseBodyText.value)
)
- // If the rawValue is already an object (from JSONPath filtering), stringify it directly
+ // If the rawValue is already an object (from JSON filtering), stringify it directly
if (typeof rawValue === "object" && rawValue !== null) {
return JSON.stringify(rawValue, null, 2)
}
@@ -404,7 +426,7 @@ const jsonBodyText = computed(() => {
const stringValue = rawValue as string
// If we're filtering, the string should already be clean JSON (no lossless numbers)
- if (filterQueryText.value.length > 0) {
+ if (debouncedFilterQuery.value.length > 0) {
return pipe(
stringValue,
O.tryCatchK(JSON.parse),
@@ -436,8 +458,8 @@ const filterResponseError = computed(() =>
E.match(
(e) => {
switch (e.type) {
- case "JSON_PATH_QUERY_FAILED":
- return { type: "JSON_PATH_QUERY_ERROR", error: e.error.message }
+ case "JSON_QUERY_FAILED":
+ return { type: "JSON_QUERY_FAILED", error: e.error.message }
case "JSON_PARSE_FAILED":
return {
type: "JSON_PARSE_FAILED",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 672f49fad..1e89c844d 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -644,6 +644,9 @@ importers:
io-ts:
specifier: 2.2.22
version: 2.2.22([email protected])
+ jq-wasm:
+ specifier: 1.1.0-jq-1.8.1
+ version: 1.1.0-jq-1.8.1
js-md5:
specifier: 0.8.3
version: 0.8.3
@@ -653,9 +656,6 @@ importers:
jsonc-parser:
specifier: 3.3.1
version: 3.3.1
- jsonpath-plus:
- specifier: 10.3.0
- version: 10.3.0
lodash-es:
specifier: 4.17.22
version: 4.17.22
@@ -4383,18 +4383,6 @@ packages:
'@jsdevtools/[email protected]':
resolution: {integrity: sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==}
- '@jsep-plugin/[email protected]':
- resolution: {integrity: sha512-VVgV+CXrhbMI3aSusQyclHkenWSAm95WaiKrMxRFam3JSUiIaQjoMIw2sEs/OX4XifnqeQUN4DYbJjlA8EfktQ==}
- engines: {node: '>= 10.16.0'}
- peerDependencies:
- jsep: ^0.4.0||^1.0.0
-
- '@jsep-plugin/[email protected]':
- resolution: {integrity: sha512-q7qL4Mgjs1vByCaTnDFcBnV9HS7GVPJX5vyVoCgZHNSC9rjwIlmbXG5sUuorR5ndfHAIlJ8pVStxvjXHbNvtUg==}
- engines: {node: '>= 10.16.0'}
- peerDependencies:
- jsep: ^0.4.0||^1.0.0
-
resolution: {integrity: sha512-L9X8uHCYU310o99L3/MpJKYxPzXPOS7S0NmBaM7UO/x2Kb2WbmMLSkfvdr1KxRIFYOpbY0Jhn7CfLSUDzL8arQ==}
@@ -9362,6 +9350,9 @@ packages:
resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==}
engines: {node: '>=10'}
+ resolution: {integrity: sha512-lWfu34lpDFIygOYcL5TzxhZIApDR9iR5XywcVoyUAZ6jlQrj8HKHOKeCcHgUm2dE9RVdbP3eqNAKGLuj+k4seQ==}
+
resolution: {integrity: sha512-hNngCeKxIUQiEUN3GPJOkz4wF/YvdUdbNL9hsBcMQTkKzboD7T/q3OYOuuPZLUE6dBxSGpwhk5mwuDud7JVAow==}
@@ -9391,10 +9382,6 @@ packages:
canvas:
optional: true
- resolution: {integrity: sha512-B7qPcEVE3NVkmSJbaYxvv4cHkVW7DQsZz13pUMrfS8z8Q/BuShN+gcTXrUlPiGqM2/t/EEaI030bpxMqY8gMlw==}
- engines: {node: '>= 10.16.0'}
-
resolution: {integrity: sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA==}
engines: {node: '>=6'}
@@ -9444,11 +9431,6 @@ packages:
resolution: {integrity: sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==}
engines: {'0': node >= 0.2.0}
- resolution: {integrity: sha512-8TNmfeTCk2Le33A3vRRwtuworG/L5RrgMvdjhKZxvyShO+mBu2fP50OWUjRLNtvw344DdDarFh9buFAZs5ujeA==}
- engines: {node: '>=18.0.0'}
- hasBin: true
-
resolution: {integrity: sha512-p/nXbhSEcu3pZRdkW1OfJhpsVtW1gd4Wa1fnQc9YLiTfAjn0312eMKimbdIQzuZl9aa9xUGaRlP9T/CJE/ditQ==}
engines: {node: '>=0.10.0'}
@@ -17231,14 +17213,6 @@ snapshots:
'@jsdevtools/[email protected]': {}
- dependencies:
- jsep: 1.4.0
-
- dependencies:
- jsep: 1.4.0
-
'@lezer/[email protected]': {}
@@ -23215,6 +23189,8 @@ snapshots:
+
@@ -23260,8 +23236,6 @@ snapshots:
- supports-color
- utf-8-validate
-
@@ -23302,12 +23276,6 @@ snapshots:
- dependencies:
- '@jsep-plugin/assignment': 1.3.0([email protected])
- '@jsep-plugin/regex': 1.0.4([email protected])
- jsep: 1.4.0
-