jsonx | Getting started

Β§ Getting Started

Get started with jsonx by following the steps below.

Β§ Install

Install as usual via NPM:

npx jsr add @fartlabs/jsonx

Or if you’re using Deno:

deno add @fartlabs/jsonx

Add the following values to your deno.json(c) file.

{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "@fartlabs/jsonx"
  }
}

Β§ Use

Add a file ending in .[j|t]sx to your project. For example, example.tsx.

function Cat() {
  return { animals: ["🐈"] };
}

function Dog() {
  return { animals: ["πŸ•"] };
}

const data = (
  <>
    <Cat />
    <Dog />
  </>
);

Deno.writeTextFileSync(
  "data.json",
  JSON.stringify(data, null, 2),
);

Compile your jsonx by running the .[j|t]sx file.

deno run --allow-write example.tsx

Preview the data.json file.

cat data.json

Resulting data.json:

{
  "animals": [
    "🐈",
    "πŸ•"
  ]
}

Learn more about JSX.