N
N
NooBick2021-01-24 11:31:14
Node.js
NooBick, 2021-01-24 11:31:14

How to make a json file?

I want to do something like this? user - variable nameacc - variable How can I implement this? {"Key": user : {"Name": nameacc}}


Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Larin, 2021-01-24
@NooBick

// Импорт модуля работы с файлами
const fs = require('fs');

// Инициализация объекта
const obj = {
  a: 'a',
  b: {
    c: 'c'
  }
};

// Перевоод объекта в JSON строку
const jsonString = JSON.stringify(obj);

// Запись JSON строки в файл
fs.writeFileSync('filename.json', jsonString);

A
Arthur, 2021-01-24
@cloudz

First make an object, then convert the object to json using stringify

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question