Skip to content

This is a custom JSON parser for validating and parsing .json files and objects through CLI or in-code.

Notifications You must be signed in to change notification settings

viralcodex/json-verifier-cli

Repository files navigation

JSON Verifier CLI (and Parser)

This is a CLI JSON verifier and parser created as a simple project from Coding challenges but now being developed as a full fledged project/package.

This tool can be used to check whether .json files are valid or not. You can verify a single file or a folder consisting of JSON files. (Any improvements or suggestions are welcome! Please raise an issue with detailed desription and requirements)

How to run

For Running in CLI

  • Open your terminal and execute:
  • npm install -g json-verifier
  • After installing, open your terminal and run json-verifier, you will get the options on how to use the tool as below.
  •   Options:
      -V, --version                   output the package version number
      -f, --file <file_path>          verify the JSON file for the file path given
      -flr, --folder <folder_path>    verify all the JSON files and parse them for the folder path given
      -d, --max-depth <number>        set the max depth for the JSON file(s) you want to check
      -l  --logging <Y/N>             Choose if you want to log the results of the verification. By default it is enabled.             
      -h, --help                      display help for available options
    

    Examples

    image

    image

    (WORK IN PROGRESS)For using the package in your code to check for JSON objects validity and parse it

  • Install the package as above, then take reference from below to import and use it
  • import jsonParser from 'json-verifier-cli';
    
    const obj = {"key":"value", "list":true}; //have to stringify before sending it as an input
    
    console.log(jsonParser(JSON.stringify(obj))); //outputs: {"key":"value", "list":true}, as it is valid
  • Note: Still is in development and may not work as intended./li>

    For Already Present Test Files in the project

  • Clone the repo and install the dependencies by running the following command:
  • npm install
  • Execute the command to run the test files present in the repository
  • npm test
  • Note: You can remove/add any test files you want and just change the directories array in index.test.js file if deleting/adding any new folder.
  • Implementation

    I would specially like to mention this repo by EliaSM which helped me craft an approach and write a version of mine. Please check their code out written in Typescript and try it out too!!(I'm still learning).

    For CLI support, I used Commander.js and Chalk.

    I use Javascript and go through character by character for the whole data and create tokens, then stop whenever there is an invalid character or pattern in the JSON data from the file. This is similar to generator function used in the above repository and this approach helps in parsing large data by not parsing it all at once but one by one and stopping whenever there is an error or invalidity is found. (Even though generator function is present in JS as well, I wrote a non-generator approach using OOPS to increase new)

    Testing

    I have used Jest for testing and test files are from Coding Challenges (folders step1 to step4) and from official JSON website (folder step5) which contains 40 standard tests for checking whether a JSON is valid or not.

    Future Updates

  • Better support to validate your JSON objects in-code by importing rather than just in CLI
  • Adding more updates soon...

    Thanks for using my project and reading till here! Any help is much appreciated!!

    About

    This is a custom JSON parser for validating and parsing .json files and objects through CLI or in-code.

    Topics

    Resources

    Stars

    Watchers

    Forks

    Packages

    No packages published