All Projects → CN-Tower → format-to-json

CN-Tower / format-to-json

Licence: MIT license
An algorithm that can format a string to json-like template. 字符串JSON格式化的算法。

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to format-to-json

JSONinSV
JSON lib in Systemverilog
Stars: ✭ 25 (-16.67%)
Mutual labels:  json-api, json-parser
json
a portable, powerful and pure functional JSON library for Scheme
Stars: ✭ 40 (+33.33%)
Mutual labels:  json-api, json-parser
Univalue
High performance RAII C++ JSON library and universal value object class
Stars: ✭ 46 (+53.33%)
Mutual labels:  json-schema, json-parser
json-ref-resolver
[Deprecated] Recursively resolve JSON pointers and remote authorities.
Stars: ✭ 27 (-10%)
Mutual labels:  json-schema, json-parser
Dictfier
Python library to convert/serialize class instances(Objects) both flat and nested into a dictionary data structure. It's very useful in converting Python Objects into JSON format
Stars: ✭ 67 (+123.33%)
Mutual labels:  json-api, json-parser
groq-cli
Run GROQ in your command line
Stars: ✭ 139 (+363.33%)
Mutual labels:  json-api, json-parser
whc-json-to-class
javascript版本json自动转换生成对应语言模型类The whc-json-to-class is the javascript plug-in that automatically converts the json string to the corresponding language model class
Stars: ✭ 24 (-20%)
Mutual labels:  json-api, json-parser
xijs
A business - oriented scene Js Library
Stars: ✭ 91 (+203.33%)
Mutual labels:  json-api, json-parser
Pyjfuzz
PyJFuzz - Python JSON Fuzzer
Stars: ✭ 342 (+1040%)
Mutual labels:  json-api, json-schema
Mojojson
A simple and fast JSON parser.
Stars: ✭ 271 (+803.33%)
Mutual labels:  json-api, json-parser
angular-json-editor
An angular wrapper for jdorn/json-editor
Stars: ✭ 93 (+210%)
Mutual labels:  json-editor, json-schema
MOSP
A collaborative platform for creating, editing and sharing JSON objects.
Stars: ✭ 72 (+140%)
Mutual labels:  json-editor, json-schema
jsonschema
A node package based on jsonschema-rs for performing JSON schema validation
Stars: ✭ 48 (+60%)
Mutual labels:  json-schema
php-json-api
JSON API transformer outputting valid (PSR-7) API Responses.
Stars: ✭ 68 (+126.67%)
Mutual labels:  json-api
babl
JSON templating on steroids
Stars: ✭ 29 (-3.33%)
Mutual labels:  json-schema
jsonSchema-to-uml
A tool to generate UML class diagrams from JSON schema documents
Stars: ✭ 33 (+10%)
Mutual labels:  json-schema
json-schema-core
A framework for building JSON Schema validators
Stars: ✭ 26 (-13.33%)
Mutual labels:  json-schema
DummyJSON
DummyJSON provides different types of REST Endpoints filled with JSON data which you can use in developing the frontend with your favorite framework and library without worrying about writing a backend.
Stars: ✭ 213 (+610%)
Mutual labels:  json-api
typescript-to-json-schema
Generate JSON schema from your Typescript sources
Stars: ✭ 54 (+80%)
Mutual labels:  json-schema
express-json-validator-middleware
Express middleware for validating requests against JSON schema
Stars: ✭ 148 (+393.33%)
Mutual labels:  json-schema

format-to-json

npm LICENSE MIT

Format string to a json like template

Usages

In HTML

<script src="https://unpkg.com/[email protected]/fmt2json.min.js"></script>
<script>
  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"}}}`;
  (async () => {
    const jsonLike = await fmt2json(source, { resultOnly: true });
    console.log(jsonLike);
  })()
</script>

In Javascript

Run: npm install format-to-json --save;

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:

{
  "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"
    }
  }
}

Interface

[Mehtod] fmt2json

fmt2json(source: string, options?: Options): Promise<Result | string>;

[Interface] Options

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] Result

// If `{ resultOnly: true }` 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;
  }
}

Terminal

Run: npm install -g format-to-json
Run: fmt2json -h

Usage: fmt2json [options]

Options:
  -V, --version          output the version number
  -v, --version          output the version number
  -i, --indent <indent>  Indnet number.
  -q, --qtMark <qtMark>  Quotation mark, one of ['""', "''", '"', "'"] (default: "\"\"")
  -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

Run: fmt2json -i 4 -q "'"

√ 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: '' }
==================================================================
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].