Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

como ler um arquivo json com javascript

const { read } = require('fs')
const readJsonFile = file => {
  if (file.split('.')[file.split('.').length - 1] !== 'json') return {}

  const fileContent = read(file)

  if (!fileContent) return {}

  return JSON.parse(fileContent)
}
readJsonFile('package.json')
 
PREVIOUS NEXT
Tagged: #como #ler #um #arquivo #json #javascript
ADD COMMENT
Topic
Name
6+7 =