Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update json-format extension #16259

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions extensions/json-format/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [Adds formatToJsonValue] - 2025-01-10

- Add a new command to format text into a valid JSON value with double quotes and escapes

## [Fix un-escaping JSON values] - 2025-01-09

- Adds a check to determine if the full payload is escaped before attemptiong to un-escape the entire payload
Expand Down
Binary file added extensions/json-format/metadata/json-format-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion extensions/json-format/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"duranbe",
"nigelang",
"cl1107",
"andy_fase"
"andy_fase",
"kricsleo"
],
"categories": [
"Data",
Expand Down Expand Up @@ -51,6 +52,12 @@
"title": "Format Array of JSON to JSONLines",
"description": "Formats an array of JSON/JS Object to JSONLines",
"mode": "view"
},
{
"name": "formatToJsonValue",
"title": "Format Text into Valid JSON Value",
"description": "Formats text into a valid JSON value with double quotes and escapes",
"mode": "view"
}
],
"preferences": [
Expand Down Expand Up @@ -107,6 +114,7 @@
"scripts": {
"build": "ray build -e dist",
"dev": "ray develop",
"publish": "npx @raycast/api@latest publish",
"lint": "ray lint",
"fix-lint": "ray lint --fix"
}
Expand Down
35 changes: 35 additions & 0 deletions extensions/json-format/src/formatToJsonValue.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Action, ActionPanel, Form } from "@raycast/api";
import { useLocalStorage } from "@raycast/utils";

export default function FormatToJsonValue() {
const { value, setValue, isLoading } = useLocalStorage<string>("json-format/format-to-json-value");

const formatted = formatJSONValue(value);

return (
<Form
isLoading={isLoading}
actions={
<ActionPanel>
<ActionPanel.Section>
<Action.CopyToClipboard title="Copy" content={formatted} />
</ActionPanel.Section>
</ActionPanel>
}
>
<Form.TextArea
id="input"
title="Input"
placeholder="Enter text to format..."
autoFocus
value={value || ""}
onChange={setValue}
/>
<Form.Description title="Formatted" text={formatted} />
</Form>
);
}

function formatJSONValue(string: string = "") {
return JSON.stringify(string);
}
Loading