Skip to content
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
2 changes: 2 additions & 0 deletions constants/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,3 +530,5 @@ pub contract Example {
}
}
`;

export const jwt = `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTcxNzg1OTU2NCwiZXhwIjoxNzE3ODYzMTY0fQ.WnYp2KahzKGxPTjIP9_IZsN48XVmaTKNTGF63gKoXhg`;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
"ts-to-zod": "^1.11.0",
"typescript": "4.3.4",
"xml-js": "^1.6.11",
"yaml": "^1.10.2"
"yaml": "^1.10.2",
"jsonwebtoken": "^8.5.1"
},
"devDependencies": {
"@types/lodash": "^4.14.170",
Expand Down
28 changes: 28 additions & 0 deletions pages/jwt-to-json.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import ConversionPanel from "@components/ConversionPanel";
import * as React from "react";
import { useCallback } from "react";
import jwt from "jsonwebtoken";

export default function JwtToJson() {
const name = "jwt-to-json";

const transformer = useCallback(async ({ value }) => {
try {
const decoded = jwt.decode(value.trim(), { complete: true });
return JSON.stringify(decoded, null, 2);
} catch (error) {
return `Error decoding JWT: ${error}`;
}
}, []);

return (
<ConversionPanel
transformer={transformer}
editorTitle="JWT"
editorLanguage="text"
editorDefaultValue="jwt"
resultTitle="JSON"
resultLanguage={"json"}
/>
);
}
6 changes: 5 additions & 1 deletion utils/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export const categorizedRoutes = [
label: "to Typescript",
path: "/js-object-to-typescript",
desc: "An online REPL for converting JS Object to Typescript."
},
}
]
},
{
Expand Down Expand Up @@ -393,6 +393,10 @@ export const categorizedRoutes = [
{
label: "Cadence to Go",
path: "/cadence-to-go"
},
{
label: "JWT to JSON",
path: "/jwt-to-json"
}
]
}
Expand Down