feat(new tool): JSON Query (lang)

Fix #1606
This commit is contained in:
ShareVB committed 2025-07-06 17:44:36 +02:00
1 parent ea0a99ef20
commit c53a8cb773
4 files changed
+101

No files matched your search

+1
View File
@@ -51,6 +51,7 @@
"@iplookup/country-extra": "^1.0.20250317", "@iplookup/country-extra": "^1.0.20250317",
"@it-tools/bip39": "^0.0.4", "@it-tools/bip39": "^0.0.4",
"@it-tools/oggen": "^1.3.0", "@it-tools/oggen": "^1.3.0",
"@jsonquerylang/jsonquery": "^5.0.4",
"@kenjiuno/decompressrtf": "^0.1.4", "@kenjiuno/decompressrtf": "^0.1.4",
"@kenjiuno/msgreader": "^1.22.0", "@kenjiuno/msgreader": "^1.22.0",
"@mdit/plugin-align": "^0.16.0", "@mdit/plugin-align": "^0.16.0",
+8
View File
@@ -50,6 +50,9 @@ dependencies:
'@it-tools/oggen': '@it-tools/oggen':
specifier: ^1.3.0 specifier: ^1.3.0
version: 1.3.0 version: 1.3.0
'@jsonquerylang/jsonquery':
specifier: ^5.0.4
version: 5.0.4
'@kenjiuno/decompressrtf': '@kenjiuno/decompressrtf':
specifier: ^0.1.4 specifier: ^0.1.4
version: 0.1.4 version: 0.1.4
@@ -4896,6 +4899,11 @@ packages:
'@jridgewell/resolve-uri': 3.1.1 '@jridgewell/resolve-uri': 3.1.1
'@jridgewell/sourcemap-codec': 1.5.0 '@jridgewell/sourcemap-codec': 1.5.0
/@jsonquerylang/jsonquery@5.0.4:
resolution: {integrity: sha512-QdgVkapeGRxUqOOJuh2svDutejKaCizhupEmO4ZKSsaLolD7w5QhgrjmBNuS1wMCM5TyNKifK4i1wBDfNzO9xQ==}
hasBin: true
dev: false
/@juggle/resize-observer@3.4.0: /@juggle/resize-observer@3.4.0:
resolution: {integrity: sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA==} resolution: {integrity: sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA==}
dev: false dev: false
+13
View File
@@ -0,0 +1,13 @@
import { Braces } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Json Query',
path: '/json-query',
description: 'Run JSON Query lang on a given JSON content',
keywords: ['json', 'query', 'jsonquery', 'lang'],
component: () => import('./json-query.vue'),
icon: Braces,
createdAt: new Date('2025-07-06'),
category: 'JSON',
});
+79
View File
@@ -0,0 +1,79 @@
<script setup lang="ts">
import JSON5 from 'json5';
import { jsonquery } from '@jsonquerylang/jsonquery';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
import { useValidation } from '@/composable/validation';
const indent = 2;
const jsonQuery = ref(`
.friends
| filter(.city == "New York")
| sort(.age)
| pick(.name, .age)
`);
const json = ref(`{
"friends": [
{ "name": "Chris", "age": 23, "city": "New York" },
{ "name": "Emily", "age": 19, "city": "Atlanta" },
{ "name": "Joe", "age": 32, "city": "New York" },
{ "name": "Kevin", "age": 19, "city": "Atlanta" },
{ "name": "Michelle", "age": 27, "city": "Los Angeles" },
{ "name": "Robert", "age": 45, "city": "Manhattan" },
{ "name": "Sarah", "age": 31, "city": "New York" }
]
}`);
const result = computed(() => {
try {
const obj = JSON5.parse(json.value);
return JSON.stringify(jsonquery(obj, jsonQuery.value), null, indent);
}
catch (e: any) {
return e.toString();
}
});
const jsonValidation = useValidation({
source: json,
rules: [
{
validator: v => JSON5.parse(v),
message: 'Provided JSON is not valid.',
},
],
});
</script>
<template>
<div>
<c-card title="Input" mb-2>
<c-input-text
v-model:value="jsonQuery"
label="JSON Query"
placeholder="Put your JSON Query string here..."
mb-2
/>
<div mb-2 flex justify-center>
<n-a target="_blank" href="https://jsonquerylang.org/docs/">
See JSON Query lang documentation
</n-a>
</div>
<c-input-text
v-model:value="json"
label="JSON"
multiline
placeholder="Put your JSON here..."
rows="5"
:validation="jsonValidation"
mb-2
/>
</c-card>
<c-card title="Result">
<TextareaCopyable :value="result" language="json" />
</c-card>
</div>
</template>