“Cómo leer un archivo JSON en el nodo JS” Código de respuesta

Leer el nodo del archivo JSON JS

function readJsonFile(file) {
    let bufferData = fs.readFileSync(file)
    let stData = bufferData.toString()
    let data = JSON.parse(stData)
    return data
}
Lucky Lion

Escribir el archivo JSON NodeJS

const fs = require('fs');
const path = require('path');

let student = { 
    name: 'Mike',
    age: 23, 
    gender: 'Male',
    department: 'English',
    car: 'Honda' 
};
 
fs.writeFileSync(path.resolve(__dirname, 'student.json'), JSON.stringify(student));
Victor Grk

node.js lee el archivo json

//Condensed
JSON.parse(fs.readFileSync("path").toString())
Thankful Toucan

Cómo obtener datos JSON del archivo JSON en el nodo JS

const fs = require("fs"); 
var posts = [];

fs.readFile('./data/posts.json', 'utf8', (err, data) => {
                if (err) throw err;
                posts = JSON.parse(data);
            });
Magnificent Millipede

Cómo leer un archivo JSON en el nodo JS

const path = require('path')
const fs = require('fs')

blogs = JSON.parse(fs.readFileSync(path.join(__dirname, '../data/blogs.json')).toString())
Strange Snake

Respuestas similares a “Cómo leer un archivo JSON en el nodo JS”

Preguntas similares a “Cómo leer un archivo JSON en el nodo JS”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código