📜 ⬆️ ⬇️

Online json generator

image Greetings

I am a JavaScript developer and have recently been developing Ext JS applications. For clarity of interfaces, it is sometimes necessary to drive JSON data into them. At first I wrote small PHP scripts to generate the necessary data, but soon it began to take more and more time and I abandoned this approach. Then I started creating * .json data files, but often I needed to have fields with a unique ID and, if possible, unique data for beauty. True, setting unique values ​​for fields, especially in an array of 100+ objects, is not a gratifying task.

And I decided to automate this process a bit.
')


I often use the service Json Parser Online . It is extremely useful in parsing the response from the server and formats JSON into a beautiful tree. But, alas, can not generate it. Inspired by this project and tired of the routine fuss, in a couple of days I wrote a small service Json Generator to generate JSON.

Implementation

In appearance, it is similar to Json Parser - this design was painfully convenient for me. The service is written in pure javascript. Only one third-party library is used - JSON-js from Douglas Crockford. There are two fields on the page: the template field of the cloned object and the field for the generated data, which are represented as a tree. The JSON template field must be valid. The generated data is enclosed in this object:
{ "id": 1, "jsonrpc": "2.0", "total": 5, //   "result": [ //  ] } 

The script understands several variables:

The template can be supplemented with any fields with any content - they will remain unchanged. The generator understands any level of nesting of objects - for all fields of nested objects containing variables, new data will be generated.

The toolbar in the middle consists of:

PS

The project is still damp, but for me it saves time well. In the future I plan to improve it and add new buns. I hope that someone will find this service useful for themselves. Thanks for attention!

UPD

Added the ability to generate arrays of objects. Their size is controlled by the variable repeat: int count . All fields in the array object may contain other variables. An example can be seen in the new template. Thank you very much taliban for the tip :)

Source: https://habr.com/ru/post/132286/


All Articles