Skip to content

wwwzbwcom/unwrap-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Unwrap JSON

Unwrap / Unescape / Decode JSON which nested many layers to prevent strange API response hurt your 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}\\\"}\"}"
});

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published