npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

any-json-no-cson

v3.2.2

Published

Convert (almost) anything to JSON.

Downloads

12

Readme

any-json

This is a folk of any-json without cson.

any-json can be used to convert (almost) anything to and from JSON.

NPM version

Install from npm

npm install any-json -g

Examples

convert

# Prints as JSON to standard out
any-json package.json5

# Writes the contents from `package.json` to `package.json5` as JSON5
any-json package.json package.json5

# Same as above (the `convert` command is default).
any-json convert package.json5
any-json convert package.json package.json5

combine

# Prints an JSON array containing an item for every JSON file in directory
any-json combine *.json

# Combines A.json and B.json, writing the result to C.json
any-json combine A.json B.json --out C.json

# Create a csv from a collection of flat YAML files
any-json combine *.yaml --out=data.csv

split

# Creates a JSON file for each row in the CSV where the name is based on the `product_id` column
any-json split products.csv prod-{product_id}.json

Formats and Data Safety

Safe

When only JSON features are used, conversion should not result in any data loss when using these formats.

  • hjson
  • json
  • json5
  • yaml

Problematic

Some loss of information may occur. Improved parsers/serializers could provide better compatibility, but implementation is provided as-is. Known issues are listed below the format.

  • ini
    • All numbers are converted to strings (the ini library would need to quote strings in order be recognize numbers)
    • In the unlikely case an object was not an array but has only has sequential, numeric members starting at zero it will be decoded as an array.
  • toml
    • Top-level array and date objects are not supported
      • It would be non-standard, but this could be worked around by wrapping the content in an object (then discarding the object when decoding).
  • xml

Limited

These formats are conceptually different and only work on a limited basis. With effort, conventions could be established to provide a more complete transfer but there will be some impedance.

Tabular formats:

  • csv
  • xls
  • xlsx

Usage

Command Line

usage: any-json [command] FILE [options] [OUT_FILE]

any-json can be used to convert (almost) anything to JSON.

This version supports:
    csv, hjson, ini, json, json5, toml, yaml

This version has is beta support for:
    xls, xlsx

The beta formats should work, but since they are new,
  behavior may change in later releases in response to feedback
  without requiring a major version update.

command:
    convert    convert between formats (default when none specified)
    combine    combine multiple documents
    split      spilts a document (containing an array) into multiple documents

options:
    -?, --help              Prints this help and exits.
    --version               Prints version information and exits.
    --input-format=FORMAT   Specifies the format of the input (assumed by file
                            extension when not provided).
    --output-format=FORMAT  Specifies the format of the output (default: json or
                            assumed by file extension when available).

  combine (additional options):
    --out=OUT_FILE          The output file.

API

const anyjson = require('any-json')
const obj = await anyjson.decode(/* string to parse */, /* format (string) */)
const str = await anyjson.encode(/* object to encode */, /* desired format (string) */)

Contributing

Contributions welcome! If any-json is not meeting your needs or your have an idea for an improvement, please open an issue or create a pull request.

History

For detailed release history, see Releases.

  • v3 Re-written to be Promise-based and bi-directional (serialization capabilities as well as parsing).
  • v2 removed the experimental/unreliable format detection.