urljson

1.0.1 • Public • Published

urljson

This module is designed to fetch JSON data from the web, and automatically parse it, and can convert JSON-based data from to/from an array/json object. It supports both HTTP & HTTPS.

Example: Getting Data (no auto parsing)

By supplying a second parameter as false in the get function, you will receive the raw data not formatted/parsed into an array.

var urljson = require('urljson');
 
urljson.get('http://website.com/ex.json', false).then(function(result) {
    console.log('RESULT => ', result, '<= Formatting (2) =>');
}, function(error) {
    console.log(error);
});

Example: Getting Data (JSON=>Array automatically)

var urljson = require('urljson');
 
urljson.get('http://website.com/ex.json', true).then(function(result) {
    console.log('RESULT => ', result);
}, function(error) {
    console.log(error);
});

This now returns an array full of the JSON data.

Example: Converting a JSON object to array

var urljson = require('urljson');
 
urljson.get('http://website.com/ex.json', false).then(function(result) {
    urljson.to_array(result).then(function(arrayData) {
        console.log(arrayData);
    }, function(err) {
        console.log(err);
    });
}, function(error) {
    console.log(error);
});

Example: Converting an array to JSON

urljson.get('http://website.com/ex.json', true).then(function(result) {
    urljson.to_json(result).then(function(jsonData) {
        console.log(jsonData);
    }, function(err) {
        console.log(err);
    });
}, function(error) {
    console.log(error);
});

Function Overview

get(url, true/false)

to_json(array of data)

to_array(json data)

Package Sidebar

Install

npm i urljson

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • cgincdev