Format string to a json like template.
npm install fmt-to-json

> Format string to a json like template
* Usages
- In HTML
- In JavaScript
* Intterface
- fmt2json
- Options
- Result
* Terminal
#### In HTML
``html`npm install format-to-json --save
#### In Javascript
Run: ;`javascript
const fmt2json = require('format-to-json');
(async () => {
const source = '{"zjson":"ZJSON","description":"Online json formatter","version":"v4.1.8","updateTime":"2018-11-23","url":"http://zjson.net","project":"http://github.com/CN-Tower/zjson","language":["中文(简体)","English"],"keywords":["zjson","json formatter"],"content":{"array":["element 001","element 002"],"boolean":true,"null":null,"number":123,"string":"Hello World","object":{"property":"value","key":"val"}}}';
fmtInfo = await fmt2json(source);
console.log(fmtInfo.result);
})();
``
Result:terminal`
{
"zjson": "ZJSON",
"description": "Online json formatter",
"version": "v4.1.8",
"updateTime": "2018-11-23",
"url": "http://zjson.net",
"project": "http://github.com/CN-Tower/zjson",
"language": [
"中文(简体)",
"English"
],
"keywords": [
"zjson",
"json formatter"
],
"content": {
"array": [
"element 001",
"element 002"
],
"boolean": true,
"null": null,
"number": 123,
"string": "Hello World",
"object": {
"property": "value",
"key": "val"
}
}
}
#### [Mehtod] fmt2json
`typescript`
fmt2json(source: string, options?: Options): Promise`
#### [Interface] Optionstypescript`
interface Options {
indent?: number; // Integer, Large then 0, default: 2
expand?: boolean; // Default: true
strict?: boolean; // Default: false
escape?: boolean; // Default: false
unscape?: boolean; // Default: false
keyQtMark?: "'" | "\"" | ""; // Default: "\""
valQtMark?: "'" | "\""; // Default: "\""
}`
#### [Interface] Resulttypescript{ resultOnly: true }
// If in option,`
// Just return the format result string.
interface Result {
result: string;
status: {
fmtLines: number;
fmtType: 'info' | 'success' | 'warning' | 'danger';
fmtSign: 'ost' | 'col' | 'val' | 'end' | 'war' | 'scc' | 'err';
message: string;
errFormat: boolean;
errIndex: number;
errExpect: string;
errNear: string;
}
}

Run: npm install -g format-to-json fmt2json -h
Run: `terminal
Usage: fmt2json [options]
Options:
-V, --version output the version number
-v, --version output the version number
-i, --indent
-q, --qtMark
-c, --collapse Collapse the formatted results.
-e, --escape Escape the formatted results.
-u, --unescape Unescape source before format.
-s, --strict Strict mode.
-r, --resultOnly Result only, not return the formatted info.
-h, --help output usage information
`fmt2json -i 4 -q "'"
Run: `terminal
√ Input a string to foramt: · [{name: "Tom", age: 28, gender: "male"}]
==================================================================
[10:42:20] format-to-json(1.0.4)
------------------------------------------------------------------
[
{
name: 'Tom',
age: 28,
gender: 'male'
}
]
------------------------------------------------------------------
{ fmtType: 'success',
fmtSign: 'scc',
fmtLines: 8,
message: 'Success formated 8 lines!',
errFormat: false,
errIndex: NaN,
errExpect: '',
errNear: '' }
==================================================================
``