How to create nested json file based on user inputs?

Viewed 427

We are working on building a product. Please see below. Here each entity on left panel is a collection in mongo db. Once the user completes filling all the forms details, need to create a json file with key-value pairs. This can be nested to any level. One rootMenuItem can have multiple MenuItems. And one menuItem can have multiple children. And so on.

screenshot

This is UI page developed in angular Js. Each collection say rootmenuItem, menuItem etc will have save button to save the key value pair

{
  "version": "19.22.02",
  "constants": {},
  "gui": {
    "screenSaver": {
      "imageId": "ACU_screensaver/MBAC_black"
    },
    "menu": [
      {
        "configId": "test",
        "tets": "RootMenuItem",
        "icon": {
          "imageId": "teste"
        },
        "primaryLabel": {
          "rawText": "test",
          "textId": "tese.0216"
        },
        "intro": {
          "imageLayers": [
            {
              "imageId": "test"
            }
          ]
        },
        "children": [
          {
            "widgetType": "test",
            "configId": "21e88e",
            "children": [
              {
                "widgetType": "Tile",
                "primaryLabel": {
                  "textId": "test",
                  "rawText": "test"
                },
                "secondaryLabel": {
                  "bindingType": "test",
                  "deviceId": "test",
                  "serviceId": 1,
                  "serviceType": 40,
                  "ifTrue": {
                    "textId": "test",
                    "rawText": "An"
                  },
                  "ifFalse": {
                    "textId": "acu1.0236",

Multiple users can create and download this json file

We are using java spring boot micro services with mongodb

The problem here is how to create a json file from this data. Please check the sample json as well. What are the best strategies to generate json faster and store the file on mongo db.

1 Answers
  1. First we will need a java object to which you can map the json.
  2. then using GSON we can convert the object to String.
  3. and then can write the String json to file using Gson fileWriter.

Here is the example: Write Json to file

Let me know:)

Related