BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/commandly/json-output

JSON Output

commandly/json-output
FreeComponent

A component for displaying formatted JSON output with syntax highlighting and copy functionality.

Live preview

live · rendered by the registry
Rendered by commandly on their own page — this is the component running, not a screenshot of it.

Install it

npx shadcn@latest add https://commandly.divyeshio.in/r/json-output.json

Source

registry/commandly/json-output.tsxcommandly.divyeshio.in/r/json-output.json · first 6 KB
1import { Tool } from "@/components/commandly/types/flat";
2import { exportToStructuredJSON } from "@/components/commandly/utils/flat";
3import { convertToNestedStructure } from "@/components/commandly/utils/nested";
4import { Badge } from "@/components/ui/badge";
5import { Button } from "@/components/ui/button";
6import { Card, CardAction, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
7import {
8 Command as UICommand,
9 CommandGroup,
10 CommandItem,
11 CommandList,
12} from "@/components/ui/command";
13import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
14import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
15import { Textarea } from "@/components/ui/textarea";
16import { cn } from "@/lib/utils";
17import { CheckIcon, ChevronsUpDownIcon, CopyIcon, Edit2Icon, XIcon } from "lucide-react";
18import { useEffect, useMemo, useState } from "react";
19import { toast } from "sonner";
20
21const jsonOptions = [
22 { value: "nested", label: "Nested" },
23 { value: "flat", label: "Flat" },
24];
25
26type DiffLine = { type: "same" | "added" | "removed"; text: string };
27
28function diffLines(before: string, after: string): DiffLine[] {
29 const a = before.split("\n");
30 const b = after.split("\n");
31 const m = a.length;
32 const n = b.length;
33 const dp = Array.from({ length: m + 1 }, () => new Array<number>(n + 1).fill(0));
34 for (let i = 1; i <= m; i++)
35 for (let j = 1; j <= n; j++)
36 dp[i][j] =
37 a[i - 1] === b[j - 1] ? dp[i - 1][j - 1] + 1 : Math.max(dp[i - 1][j], dp[i][j - 1]);
38 const result: DiffLine[] = [];
39 let i = m,
40 j = n;
41 while (i > 0 || j > 0) {
42 if (i > 0 && j > 0 && a[i - 1] === b[j - 1]) {
43 result.unshift({ type: "same", text: a[i - 1] });
44 i--;
45 j--;
46 } else if (j > 0 && (i === 0 || dp[i][j - 1] >= dp[i - 1][j])) {
47 result.unshift({ type: "added", text: b[j - 1] });
48 j--;
49 } else {
50 result.unshift({ type: "removed", text: a[i - 1] });
51 i--;
52 }
53 }
54 return result;
55}
56
57interface JsonTypeComponentProps {
58 tool: Tool;
59 originalTool?: Tool;
60 onApply?: (tool: Tool) => void;
61}
62
63export function JsonOutput({ tool, originalTool, onApply }: JsonTypeComponentProps) {
64 const [open, setOpen] = useState(false);
65 const [jsonString, setJsonString] = useState<string>();
66 const [originalJsonString, setOriginalJsonString] = useState<string>();
67 const [jsonType, setJsonType] = useState<"nested" | "flat">("flat");
68 const [isEditing, setIsEditing] = useState(false);
69// … truncated

What it pulls in

npm packages

  • react

Other registry items

  • button
  • scroll-area

Files it writes

  • registry/commandly/json-output.tsx
  • registry/commandly/types/flat.ts
  • registry/commandly/types/nested.ts
  • registry/commandly/utils/flat.ts
  • registry/commandly/utils/nested.ts

Facts

Registry
commandly
Type
registry:component
Access
Free
Files written
5
Licence
MIT
First indexed
2026-08-01
Last confirmed
2 days ago

Go to the source

Docs on commandly commandly.divyeshio.in divyeshio/commandly on GitHub Raw registry item This item as JSON

More from commandly

All 4 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Generated Commandgenerated-commandcommandlyComponentsFree3 deps · 5 files
Tool Renderertool-renderercommandlyComponentsFree1 dep · 4 files
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex