unwrap-json
v1.0.3
Published
Unwrap / Unescape / Decode JSON which nested many layers to prevent strange API response hurt your eyes :eyes:
Downloads
1
Readme
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}\\\"}\"}"
});