Skip to content

bintastic / json

Function: json()

json(strings, ...values): string

Defined in: json.ts:57

Creates JSON file content from a template string.

The template is parsed as JSON and returned as normalized JSON.stringify output, so original whitespace and formatting are not preserved and comments (JSONC) are not supported. Interpolated values are serialized with JSON.stringify before parsing. No trailing newline is added; append one explicitly if the file requires it.

Note: package.json is special-cased by fixturify-project and is serialized from the project's pkg, not from files, so assigning json content to files['package.json'] has no effect. Configure it via the project constructor or project.pkg instead.

Parameters

strings

TemplateStringsArray

The JSON template string segments.

values

...unknown[]

Values to serialize into the JSON template.

Returns

string

The normalized JSON file content.

Example

ts
import { json } from 'bintastic';

project.files = {
  'tsconfig.json': json`{ "compilerOptions": { "strict": true } }`,
  'data.json': json`{ "count": ${42}, "enabled": ${true} }`,
};
await project.write();