Home > front end >  How to write this Json properly
How to write this Json properly

Time:03-08

Im writing a Json api and the input is like this. How can i type this properly in json? The input is Json in Strapi API

Category 1:
   {
     Name : x
     Price: y
     Url: z
    }
   {
     Name : a
     Price: b
     Url: c
    }
   {
     Name : d
     Price: e
     Url: f
    }
Category 2:

Another array

still have the issue in mapping :

still have the issue Warning: Encountered two children with the same key, `1`. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.

CodePudding user response:

The following structure will work just fine for your use case:

{
  "categories": {
    "Category 1": [
      {
        "Name": "x",
        "Price": "y",
        "Url": "z"
      },
      {
        "Name": "a",
        "Price": "b",
        "Url": "c"
      },
      {
        "Name": "d",
        "Price": "e",
        "Url": "f"
      }
    ],
    "Category 2": [
      {
        "Name": "x",
        "Price": "y",
        "Url": "z"
      },
      {
        "Name": "a",
        "Price": "b",
        "Url": "c"
      },
      {
        "Name": "d",
        "Price": "e",
        "Url": "f"
      }
    ]
  }
}

  • Related