add json to go bson (works for mongo-driver) (#145)

This commit is contained in:
Guilherme Esteves authored and Ritesh Kumar committed 2019-10-04 01:50:49 +05:30
1 parent 521a050c4e
commit 69cf8c183a
2 files changed
+28

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
import ConversionPanel, { Transformer } from "@components/ConversionPanel";
import * as React from "react";
import { useCallback } from "react";
export default function() {
const transformer = useCallback<Transformer>(async ({ value }) => {
return JSON.stringify(JSON.parse(value || "{}"), null, 2)
.replace(/\{/gm, "bson.M{")
.replace(/\[/gm, "bson.A{")
.replace(/\]/gm, "}")
.replace(/(\d|\w|")$/gm, "$1,")
.replace(/(\}$)(\n)/gm, "$1,$2");
}, []);
return (
<ConversionPanel
transformer={transformer}
editorTitle="JSON"
editorLanguage="json"
resultTitle="Go Bson"
resultLanguage={"go"}
/>
);
}
+4
View File
@@ -110,6 +110,10 @@ export const categorizedRoutes = [
packageName: "json-to-go",
packageUrl: "https://github.com/mholt/json-to-go"
},
{
label: "to Go Bson",
path: "/json-to-go-bson"
},
{
label: "to YAML",
path: "/json-to-yaml",