
Security News
Open VSX Begins Implementing Pre-Publish Security Checks After Repeated Supply Chain Incidents
Following multiple malicious extension incidents, Open VSX outlines new safeguards designed to catch risky uploads earlier.
@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 3 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
Following multiple malicious extension incidents, Open VSX outlines new safeguards designed to catch risky uploads earlier.

Research
/Security News
Threat actors compromised four oorzc Open VSX extensions with more than 22,000 downloads, pushing malicious versions that install a staged loader, evade Russian-locale systems, pull C2 from Solana memos, and steal macOS credentials and wallets.

Security News
Lodash 4.17.23 marks a security reset, with maintainers rebuilding governance and infrastructure to support long-term, sustainable maintenance.