Skip to content
This repository was archived by the owner on Sep 2, 2023. It is now read-only.
This repository was archived by the owner on Sep 2, 2023. It is now read-only.

Feature: Import JSON without needing asynchronous syntax #114

Closed
@GeoffreyBooth

Description

@GeoffreyBooth

Updated feature request description:

Imagine code like this in current Node:

const packageJson = JSON.parse(fs.readFileSync('./package.json'));
console.log(`Running version ${packageJson.version}`);

This can also be written as:

const packageJson = require('./package.json');
console.log(`Running version ${packageJson.version}`);

Both of these examples are written without asynchronous syntax on the user’s part: there are no callbacks, no promises, no await. Perhaps Node is doing asynchronous stuff behind the scenes, but the user is unaware of it. require appears to be as synchronous as readFileSync.

This feature request is that a user’s code to import JSON files via ESM should be like these examples: no callbacks, no promises, no await. This feature request doesn’t concern Node’s implementation under the hood, and whether it is synchronous or asynchronous; the request is only that the user’s code be able to be written in a synchronous style.

Use case 48. Part of #100.


Original feature request description:

ESM imports of JSON can be written in a synchronous style:

import { version } from './package.json';
console.log(`Running version ${version}`);

The point of this feature is that users can use the same synchronous style of coding (in the vein of fs.readFileSync as opposed to callback- or promise-based alternatives) when the import is of JSON. Or put another way, users aren’t required to use await or promises or other asynchronous constructs in code in order to import JSON.

Use case 48. Part of #100.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions