1.0.3 • Published 3 years ago

unwrap-json v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Unwrap JSON

Unwrap / Unescape / Decode JSON which nested many layers to prevent strange API response hurt your eyes :eyes:

Before

{
    "code": 0,
    "error": null,
    "timestamp": 1631877538538,
    "data": "{\"code\":0,\"error\":null,\"timestamp\":1631877538538,\"data\":\"{\\\"code\\\":0,\\\"error\\\":null,\\\"timestamp\\\":1631877538538,\\\"data\\\":\\\"{\\\\\\\"code\\\\\\\":0,\\\\\\\"error\\\\\\\":null,\\\\\\\"timestamp\\\\\\\":1631877538538}\\\"}\"}"
}

After

{
    "code": 0,
    "error": null,
    "timestamp": 1631877538538,
    "data": {
        "code": 0,
        "error": null,
        "timestamp": 1631877538538,
        "data": {
            "code": 0,
            "error": null,
            "timestamp": 1631877538538,
            "data": {
                "code": 0,
                "error": null,
                "timestamp": 1631877538538
            }
        }
    }
}

Usage

Install

npm i unwrap-json

Stdin Input and Stdout Output

unwrap-json
{
    "code": 0,
    "error": null,
    "timestamp": 1631877538538,
    "data": "{\"code\":0,\"error\":null,\"timestamp\":1631877538538,\"data\":\"{\\\"code\\\":0,\\\"error\\\":null,\\\"timestamp\\\":1631877538538,\\\"data\\\":\\\"{\\\\\\\"code\\\\\\\":0,\\\\\\\"error\\\\\\\":null,\\\\\\\"timestamp\\\\\\\":1631877538538}\\\"}\"}"
}

# {
#     "code": 0,
#     "error": null,
#     "timestamp": 1631877538538,
#     "data": {
#         "code": 0,
#         "error": null,
#         "timestamp": 1631877538538,
#         "data": {
#             "code": 0,
#             "error": null,
#             "timestamp": 1631877538538,
#             "data": {
#                 "code": 0,
#                 "error": null,
#                 "timestamp": 1631877538538
#             }
#         }
#     }
# }

File Input

unwrap-json < input.json

File Output

unwrap-json > output.json

File Input and File Output

unwrap-json < input.json > output.json

Programmatic Usage

const { unwrapJson } = require('unwrap-json');
unwrapJson({
    "code": 0,
    "error": null,
    "timestamp": 1631877538538,
    "data": "{\"code\":0,\"error\":null,\"timestamp\":1631877538538,\"data\":\"{\\\"code\\\":0,\\\"error\\\":null,\\\"timestamp\\\":1631877538538,\\\"data\\\":\\\"{\\\\\\\"code\\\\\\\":0,\\\\\\\"error\\\\\\\":null,\\\\\\\"timestamp\\\\\\\":1631877538538}\\\"}\"}"
});
1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago