Creation of JSON with numeral

-1

I would like to create a JSON like this (this is only a part), I always create the object with the value, but I can not do it this way using 200 as an object:

path.get.response = new Object()
path.get.response.200 = new Object()

  "responses": {
      "200": {
        "description": "Operação realizada com sucesso!",
        "content": {
          "application/json": {
            "schema": {

....

    
asked by anonymous 16.11.2018 / 13:11

1 answer

1

Is it really necessary to name the object as 200? I believe that objects can not start with number , hyphen , or special character . Maybe the ideal would be to call it status200 or S200 , finally it depends on your creativity.

  

A property name of an object can be any string   Valid JavaScript, or anything that can be converted into a   string, including an empty string. However, any name and   property that is not a valid JavaScript identifier (for example,    a property name that has a space or a hyphen, or that begins   with a number ) can only be accessed (a) using the notation of   brackets [...]

You can check out more in this article - Working with Objects

    
16.11.2018 / 14:28