Skip to content

readJsonFile

Lit et parse un fichier JSON.

Exemple

ts
import { 
SF
} from "@duplojs/server-utils";
import {
E
, type
ExpectType
,
unwrap
} from "@duplojs/utils";
const
config
= await
SF
.
readJsonFile
("/tmp/config.json");
// config: E.Success<unknown> | SF.FileSystemLeft const
result
= await
SF
.
readJsonFile
<{
content
: string }>("/tmp/data.json");
if (
E
.
isRight
(
result
)) {
const
data
=
unwrap
(
result
);
type
check
=
ExpectType
<
typeof
data
,
{
content
: string },
"strict" >; }

Syntaxe

typescript
function readJsonFile<GenericOutput>(
  path: string | URL
): Promise<FileSystemLeft | E.Success<GenericOutput>>

Paramètres

  • path : chemin du fichier JSON.

Valeur de retour

  • E.Success<GenericOutput> : contenu JSON parse.
  • FileSystemLeft : si la lecture ou le parse échoue.

Voir aussi

Diffusé sous licence MIT.