
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
@jlarky/json-to-javascript
Advanced tools
Convert JSON data to JavaScript code literals with smart handling of multiline strings.
Convert JSON data to JavaScript code literals with smart handling of multiline strings.
This tool transforms JSON into properly formatted JavaScript code, automatically converting multiline strings into template literals with dedent support for clean indentation.
Input file (input.json):
{
"greeting": "Hello\nWorld",
"message": "Line 1\nLine 2\nLine 3",
"count": 42
}
Node.js:
npx @jlarky/json-to-javascript \
--inputFile input.json \
--outputFile output.ts \
--useDedent true \
--prefix "import dedent from 'dedent'; export const data = (" \
--suffix ") as const" \
--prettierOptions '{"parser":"babel-ts"}'
Bun:
bunx @jlarky/json-to-javascript \
--inputFile input.json \
--outputFile output.ts \
--useDedent true \
--prefix "import dedent from 'dedent'; export const data = (" \
--suffix ") as const" \
--prettierOptions '{"parser":"babel-ts"}'
Deno:
deno run --allow-sys=cpus --allow-env --allow-read=. --allow-write=. \
jsr:@jlarky/json-to-javascript/cli \
--inputFile input.json \
--outputFile output.ts \
--useDedent true \
--prefix "import dedent from 'dedent'; export const data = (" \
--suffix ") as const" \
--prettierOptions '{"parser":"babel-ts"}'
Output file (output.ts):
import dedent from "dedent";
export const data = {
greeting: dedent`
Hello
World
`,
message: dedent`
Line 1
Line 2
Line 3
`,
count: 42,
} as const;
npx @jlarky/json-to-javascript \
--inputFile input.json \
--outputFile output.js
This outputs the same JSON with default prefix ( and suffix ):
({
greeting: "Hello\nWorld",
message: "Line 1\nLine 2\nLine 3",
count: 42,
});
The difference from the previous example: no custom prefix/suffix, import statement, or dedent - just the data wrapped in parentheses with escaped newlines.
json-to-javascript [options]
Required:
--inputFile <path> Input JSON file
--outputFile <path> Output JavaScript file
Optional:
--prefix <string> Prefix for output (default: "(")
--suffix <string> Suffix for output (default: ")")
--usePrettier <boolean> Format with Prettier (default: true)
--prettierOptions <json> Prettier options as JSON string
--useDedent <boolean> Convert multiline strings to template literals
--dedentPrefix <string> Prefix for dedent (default: " dedent")
--dedentSuffix <string> Suffix for dedent (default: "")
--jsonStringifySpace <number> Indentation spaces for JSON.stringify
--help Show help
If you want to use the library in your code or install it locally:
deno add jsr:@jlarky/json-to-javascript
bunx jsr add @jlarky/json-to-javascript # or bun add @jlarky/json-to-javascript
npx jsr add @jlarky/json-to-javascript # or npm install @jlarky/json-to-javascript
import { jsonToJavascript } from "@jlarky/json-to-javascript";
const data = { name: "John", age: 30 };
const result = await jsonToJavascript(data);
console.log(result.code); // ({ name: "John", age: 30 });
See CONTRIBUTING.md for development setup, testing, and publishing guidelines.
MIT
FAQs
Convert JSON data to JavaScript code literals with smart handling of multiline strings.
The npm package @jlarky/json-to-javascript receives a total of 2 weekly downloads. As such, @jlarky/json-to-javascript popularity was classified as not popular.
We found that @jlarky/json-to-javascript demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.