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

jsoun

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsoun

Ever wanted to put json in a url and thought it was ugly? JSOUN (Javascript Object URL Notation) makes it slightly better

  • 0.0.2
  • npm
  • Socket score

Version published
Weekly downloads
16
increased by33.33%
Maintainers
1
Weekly downloads
 
Created
Source

Ever wanted to put JSON in a url? It's ugly, right?

To make it slightly better, you can use JSOUN (Javascript Object URL Notation).

Example

const jsoun = require('jsoun')
var obj = {
  "store":{
    "book":[
      {
        "category":"reference",
        "author":"Nigel Rees",
        "title":"Sayings of the Century",
        "price":8.95
      },
      {
        "category":"fiction",
        "author":"Evelyn Waugh",
        "title":"Sword of Honour",
        "price":12.99
      },
      {
        "category":"fiction",
        "author":"J. R. R. Tolkien",
        "title":"The Lord of the Rings",
        "isbn":"0-395-19395-8",
        "price":22.99
      }
    ],
    "bicycle":{
      "color":"red",
      "price":19.95
    }
  }
}
var compact = JSON.stringify(obj)
var jsoun = jsoun(compact)
var url1 = encodeURI(compact)
var url2 = encodeURI(jsoun)

console.log('Compact JSON:')
console.log(compact)
console.log(compact.length+' chars')
console.log('\nAfter URL Encode:')
console.log(url1)
console.log(url1.length+' chars')
console.log('\nJSOUN:')
console.log(jsoun)
console.log(jsoun.length+' chars')
console.log('\nAfter URL Encode:')
console.log(url2)
console.log(url2.length+' chars')

// Compact JSON:
// {"store":{"book":[{"category":"reference","author":"Nigel Rees","title":"Sayings of the Century","price":8.95},{"category":"fiction","author":"Evelyn Waugh","title":"Sword of Honour","price":12.99},{"category":"fiction","author":"J. R. R. Tolkien","title":"The Lord of the Rings","isbn":"0-395-19395-8","price":22.99}],"bicycle":{"color":"red","price":19.95}}}
// 360 chars

// After URL Encode:
// %7B%22store%22:%7B%22book%22:%5B%7B%22category%22:%22reference%22,%22author%22:%22Nigel%20Rees%22,%22title%22:%22Sayings%20of%20the%20Century%22,%22price%22:8.95%7D,%7B%22category%22:%22fiction%22,%22author%22:%22Evelyn%20Waugh%22,%22title%22:%22Sword%20of%20Honour%22,%22price%22:12.99%7D,%7B%22category%22:%22fiction%22,%22author%22:%22J.%20R.%20R.%20Tolkien%22,%22title%22:%22The%20Lord%20of%20the%20Rings%22,%22isbn%22:%220-395-19395-8%22,%22price%22:22.99%7D%5D,%22bicycle%22:%7B%22color%22:%22red%22,%22price%22:19.95%7D%7D%7D
// 532 chars

// Magic JSON:
// ('store':('book':~('category':'reference','author':'Nigel_Rees','title':'Sayings_of_the_Century','price':8.95),('category':'fiction','author':'Evelyn_Waugh','title':'Sword_of_Honour','price':12.99),('category':'fiction','author':'J._R._R._Tolkien','title':'The_Lord_of_the_Rings','isbn':'0-395-19395-8','price':22.99);,'bicycle':('color':'red','price':19.95)))
// 360 chars

// After URL Encode:
// ('store':('book':~('category':'reference','author':'Nigel_Rees','title':'Sayings_of_the_Century','price':8.95),('category':'fiction','author':'Evelyn_Waugh','title':'Sword_of_Honour','price':12.99),('category':'fiction','author':'J._R._R._Tolkien','title':'The_Lord_of_the_Rings','isbn':'0-395-19395-8','price':22.99);,'bicycle':('color':'red','price':19.95)))
// 360 chars

Note

JSOUN is only 100% safe in the fragment part of the url, i.e. after the # delimiter.

Keywords

FAQs

Package last updated on 03 Mar 2020

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