F
F
Felino2018-07-31 11:38:50
Angular
Felino, 2018-07-31 11:38:50

Angular Json error?

Hello!
Tell me if it's not difficult!

[
  {
    "general": {
      "firstName": "Liana",
      "lastName": "Crooks",
      "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/kevinoh/128.jpg"
    },
    "job": {
      "company": "Ledner, Johnson and Predovic",
      "title": "Investor Functionality Coordinator"
    },
    "contact": {
      "email": "[email protected]",
      "phone": "(895) 984-0132"
    },
    "address": {
      "street": "1520 Zemlak Cove",
      "city": "New Devon",
      "zipCode": "42586-7898",
      "country": "Guinea-Bissau"
    }
  },
  {
    "general": {
      "firstName": "Deontae",
      "lastName": "Dare",
      "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/andysolomon/128.jpg"
    },
    "job": {
      "company": "D'Amore, Dicki and Borer",
      "title": "International Applications Consultant"
    },
    "contact": {
      "email": "[email protected]",
      "phone": "1-615-843-3426 x600"
    },
    "address": {
      "street": "65901 Glover Terrace",
      "city": "Alden ton",
      "zipCode": "57744-4248",
      "country": "Kenya"
    }
  }
]

I run "server": "json-server --watch test.json --port 3000"
Error: Data must be an object. Found object. See https://github.com/typicode/json-server for example.
Prompt in what there can be a trabl? I can't figure out what's wrong with JSON. I understand that it does not find the object. But when I make an object other errors come up!
here is an example!
{
    "general": [{
      "firstName": "Liana",
      "lastName": "Crooks",
      "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/kevinoh/128.jpg"
    }],
    "job": [{
      "company": "Ledner, Johnson and Predovic",
      "title": "Investor Functionality Coordinator"
    }],
    "contact": [{
      "email": "[email protected]",
      "phone": "(895) 984-0132"
    }],
    "address": [{
      "street": "1520 Zemlak Cove",
      "city": "New Devon",
      "zipCode": "42586-7898",
      "country": "Guinea-Bissau"
    }]
  },
  {
    "general": [{
      "firstName": "Deontae",
      "lastName": "Dare",
      "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/andysolomon/128.jpg"
    }],
    "job": [{
      "company": "D'Amore, Dicki and Borer",
      "title": "International Applications Consultant"
    }],
    "contact": [{
      "email": "[email protected]",
      "phone": "1-615-843-3426 x600"
    }],
    "address": [{
      "street": "65901 Glover Terrace",
      "city": "Alden ton",
      "zipCode": "57744-4248",
      "country": "Kenya"
    }]
  }

SyntaxError: Malformed JSON in file: clients.json
Unexpected token ',' at 21:4
},
^

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Eremin, 2018-07-31
@Felino

  1. Open https://jsoneditoronline.org/
    Possible solutions:
    array
    [
      {
        "general": [
          {
            "firstName": "Liana",
            "lastName": "Crooks",
            "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/kevinoh/128.jpg"
          }
        ],
        "job": [
          {
            "company": "Ledner, Johnson and Predovic",
            "title": "Investor Functionality Coordinator"
          }
        ],
        "contact": [
          {
            "email": "[email protected]",
            "phone": "(895) 984-0132"
          }
        ],
        "address": [
          {
            "street": "1520 Zemlak Cove",
            "city": "New Devon",
            "zipCode": "42586-7898",
            "country": "Guinea-Bissau"
          }
        ]
      },
      {
        "general": [
          {
            "firstName": "Deontae",
            "lastName": "Dare",
            "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/andysolomon/128.jpg"
          }
        ],
        "job": [
          {
            "company": "D'Amore, Dicki and Borer",
            "title": "International Applications Consultant"
          }
        ],
        "contact": [
          {
            "email": "[email protected]",
            "phone": "1-615-843-3426 x600"
          }
        ],
        "address": [
          {
            "street": "65901 Glover Terrace",
            "city": "Alden ton",
            "zipCode": "57744-4248",
            "country": "Kenya"
          }
        ]
      }
    ]
    An object
    {
      "a": {
        "general": [
          {
            "firstName": "Liana",
            "lastName": "Crooks",
            "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/kevinoh/128.jpg"
          }
        ],
        "job": [
          {
            "company": "Ledner, Johnson and Predovic",
            "title": "Investor Functionality Coordinator"
          }
        ],
        "contact": [
          {
            "email": "[email protected]",
            "phone": "(895) 984-0132"
          }
        ],
        "address": [
          {
            "street": "1520 Zemlak Cove",
            "city": "New Devon",
            "zipCode": "42586-7898",
            "country": "Guinea-Bissau"
          }
        ]
      },
      "b": {
        "general": [
          {
            "firstName": "Deontae",
            "lastName": "Dare",
            "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/andysolomon/128.jpg"
          }
        ],
        "job": [
          {
            "company": "D'Amore, Dicki and Borer",
            "title": "International Applications Consultant"
          }
        ],
        "contact": [
          {
            "email": "[email protected]",
            "phone": "1-615-843-3426 x600"
          }
        ],
        "address": [
          {
            "street": "65901 Glover Terrace",
            "city": "Alden ton",
            "zipCode": "57744-4248",
            "country": "Kenya"
          }
        ]
      }
    }
    An array in an object is the most appropriate
    {
      "data": [
        {
          "general": {
            "firstName": "Liana",
            "lastName": "Crooks",
            "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/kevinoh/128.jpg"
          },
          "job": {
            "company": "Ledner, Johnson and Predovic",
            "title": "Investor Functionality Coordinator"
          },
          "contact": {
            "email": "[email protected]",
            "phone": "(895) 984-0132"
          },
          "address": {
            "street": "1520 Zemlak Cove",
            "city": "New Devon",
            "zipCode": "42586-7898",
            "country": "Guinea-Bissau"
          }
        },
        {
          "general": {
            "firstName": "Deontae",
            "lastName": "Dare",
            "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/andysolomon/128.jpg"
          },
          "job": {
            "company": "D'Amore, Dicki and Borer",
            "title": "International Applications Consultant"
          },
          "contact": {
            "email": "[email protected]",
            "phone": "1-615-843-3426 x600"
          },
          "address": {
            "street": "65901 Glover Terrace",
            "city": "Alden ton",
            "zipCode": "57744-4248",
            "country": "Kenya"
          }
        }
      ]
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question