Socket
Socket
Sign inDemoInstall

async-json-parser

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    async-json-parser

## parse


Version published
Maintainers
1
Install size
292 kB
Created

Readme

Source

Async JSON parser

parse

import { parse } from 'async-json-parser';
import request from 'request';

const URL = 'http://auction-api-eu.worldofwarcraft.com/auction-data/258993a3c6b974ef3e6f22ea6f822720/auctions.json';

const get = (url) => {
  return new Promise(resolve => {
    request(url, (res, err, body) => {
      resolve(body)
    })
  })
};

(async () => {
  
  /* pass data as string */
  
  const data = await get(URL);
  const result = await parse(data);
  
  /* ------------------ */
  
  /* pass data as stream */
  
  await parse(request(URL));
  
  /* ------------------ */
  
})();

Parser

import Parser from 'async-json-parser/parser'

(async () => {
  const str = JSON.stringify(someObject);
  const parser = new Parser();
  await parser.parse(str);
  console.log(parser.get());
})()

parse stream

import fs from 'fs';
import {parse} from 'async-json-parser';
import json from './test.json';

(async () => {
  const stream = fs.createReadStream('test.json');
  const res = await parse(stream);
  console.log(+res['a1'][0].address.geo.lat === -37.3159);
  console.log(res['a457'][2].address.suite === 'Suite 847');
})();

stringify

import fs from 'fs';
import {stringify} from 'async-json-parser';
import json from './test.json';

(async () => {
  const data = await stringify(json);
  fs.writeFileSync('data.json', data);
})();

Keywords

FAQs

Last updated on 25 Sep 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc