Skip to content

jokly/JSON-Sanitizer

Repository files navigation

JSON-Sanitizer

Build Status

Requirements

  1. Virtual Box
  2. Vagrant >= 2.0
  3. Plugin vagrant-vbguest (vagrant plugin install vagrant-vbguest)

Installation

  1. git clone https://github.com/jokly/JSON-Sanitizer.git
  2. cd JSON-Sanitizer
  3. vagrant plugin install vagrant-vbguest
  4. vagrant up

How to run tests and code coverage

  1. vagrant ssh
  2. cd /vagrant
  3. make test
  4. make coverage

Available types

  1. Integer

    {
        "data": "3",
        "type": "int"
    }
  2. Float

    {
        "data": "-5.3",
        "type": "float"
    }
  3. String

    {
        "data": "Hello World!",
        "type": "string"
    }
  4. Phone number

    {
        "data": "8(950)288-56-23",
        "type": "phone"
    }
  5. Array

    {
        "data": [
            {
                "data": "-5",
                "type": "int"
            },
            {
                "data": "3.25",
                "type": "float"
            }
        ],
        "type": "array"
    }
  6. Typed array

    {
        "data": [
            {
                "data": "Hello",
                "type": "string"
            },
            {
                "data": "World!",
                "type": "string"
            }
        ],
        "type": "array:string"
    }
  7. Dictionary

    {
        "data": {
            "my_str": {
                "data": "Hello",
                "type": "string"
            },
            "secod_el": {
                "data": "79.1",
                "type": "float"
            }
        },
        "type": "dict"
    }

JSON data example

[
    {
        "data": "15",
        "type": "int"
    },
    {
        "data": "7.1",
        "type": "float"
    }
]

Errors

  1. InvalidJsonException

    "Invalid json object"
  2. UndefinedIndexException

    "Undefinde index: <index>"
  3. UnknownTypeException

    "Unknown type: <type>"
  4. RequiredTypeException

    "Element must be of the type <required_type>, <given type> given"
  5. UnexpectedTypeException

    "Unexpected type: <type>"
  6. InvalidTypeException => { InvalidIntException, InvalidFloatException, InvalidPhoneException }

    "Invalid <expected type: integer/float/phone>: <invalid data>"

Errors example

{
    "errors": [
        {
            "msg": "Undefinde index: 'data'"
        },
        {
            "msg": "Invalid 'integer': '5.1'"
        }
    ]
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published