Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json2plain

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json2plain

Convert JSON structure to plain text, perfect as a content negotiation fallback in REST APIs

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-42.86%
Maintainers
1
Weekly downloads
 
Created
Source

JSON2Plain

JSON in, Plain text out.

The json2plain module was written as a suitable final fallback for a REST API doing automatic content negotiation.

Installation

$ npm install json2plain

Usage

var json2plain = require('json2plain');

var plain = json2plain(json, options);

Parameters

  • json - Can be a JSON Object or valid JSON String.
  • options - Optional Object, options are listed below.

Simple Example

var json2plain = require('json2plain');

var json = {
  "code": 7489394874,
  "error": "It don't workie",
  "description": "Someone broke it."
};

var plain = json2plain(json);
console.log(plain);
Code: 7489394874
Error: It don't workie
Description: Someone broke it.

More Advanced Example

var json2plain = require('json2plain');

var json = { 
  hello: "world",
  number: 48392,
  array: [
    'string',
    3948484,
    true,
    'string'
  ], "object": {
    "string": "hello again",
    "another": {
      "hey": "there"
    }   
  }
};

function ucFirst(string) {
  return string.charAt(0).toUpperCase() + string.slice(1);
}

var options = { 
  list: '* ',
  indent: '   ',
  separator: '\t=\t',
  formatKey: ucFirst,
  formatValue: ucFirst
};

var plain = json2plain(json, options);
console.log(plain);
Hello	=	World
	Number	=	48392
	Array	=	
		* String
		* 3948484
		* True
		* String
	Object	=	
	String	=	Hello again
		Another	=	
			Hey	=	There

Options

  • depth {Number} - amount of indentation to start with, defaults to 1.
  • newline {String} - string to use for newline, defaults to '\n'.
  • indent {String} - indentation, defaults to two spaces: ' '.
  • separator {String} - used to separate key from value, default: ': '.
  • prefix {String} - inserted before the output, defaults to '\n'.
  • suffix {String} - appended to the final output, defaults to '\n'.
  • list {String} - 'numbered' will list numbered array keys, defaults to '- '.
  • formatKey {Function} - format the keys: function(key){return key.toUpperCase()}..
  • formatVal {Function} - format the values: function(val) {return val}.

Please see the examples folder for working examples of json2plain in action.

License

(The MIT License)

Copyright (c) 2012 Jarrad Seers <jarrad@jarradseers.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Package last updated on 24 Feb 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