New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

js-json

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-json

easy js to json parser

  • 0.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Преобразует JS в JSON

допустим берем такой js-json файл example.json

{
	aaa: 777,
	bbb: 'ccc eee',
	"ddd": {
		, eee: 1  // xxxx
		, uuu: 2
	},

	/*
		bla bla bla bla
		bla bla bla bla
	*/

	qqq: [
		, 'sssss ssss'
		, 'ggg "ggg" gg'
	]
}

как json этот файл не валиден. но его можно преобразовать в правильный json и распарсить стандартными средствами

var jsjson = require('js-json');

require('fs').readFile('./example.json', function (err, data) {
	if (err) {
		console.log('file:// not load');
		return;
	};

	var data = data.toString('utf8');
	if (data.charCodeAt(0) === 65279) {
		data = data.substr(1); // UTF8 BOM
	};

	console.log( jsjson.parse(data) );

});

в итоге получаем следующий обьект

{
	aaa: 777,
	bbb: 'ccc eee',
	ddd: {
		eee: 1,
		uuu: 2 
	},
	qqq: [
		'sssss ssss',
		'ggg "ggg" gg'
	]
}

Keywords

FAQs

Package last updated on 22 Sep 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc