JSON parse error - Expecting property name enclosed in double quotes: line 11 column 5 (char 257)"

Viewed 4073

I am following a course on the Django Rest Framework. I seem to have copied the code verbatim, however, there seems to be some error which I am unable to zero down on. What possibly could be causing this error?

Basically, I am testing the model serializer. I am trying to post the following data.

{
        "id": 1,
        "author": "John Doe",
        "title": "Happy Birthday",
        "description": "20 years of ISS",
        "body": "Fancy content",
        "location": "Earth",
        "publication_date": "2020-06-11",
        "active": false,

    }

My serializer class looks:

class ArticleSerializer(serializers.ModelSerializer):

    time_since_publication = serializers.SerializerMethodField()

    class Meta:
        model = Article
        fields = '__all__'

    def get_time_since_publication(self, object):
        publication_date = object.publication_date
        now = datetime.now()
        time_delta = timesince(publication_date, now)
        return time_delta

And my model is :

class Article(models.Model):
    author = models.CharField(max_length=50)
    title = models.CharField(max_length=120)
    description = models.CharField(max_length=200)
    body = models.TextField()
    location = models.CharField(max_length=120)
    publication_date = models.DateField()
    active = models.BooleanField()
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def __str__(self):
        return f"{self.author} {self.title}"

The error thrown is a 400 BAD REQUEST error:

{
    "detail": "JSON parse error - Expecting property name enclosed in double quotes: line 13 column 1 (char 214)"
}
2 Answers

There is extra ',' "active": false,

Remove the ,

  {
    "id": 1,
    "author": "John Doe",
    "title": "Happy Birthday",
    "description": "20 years of ISS",
    "body": "Fancy content",
    "location": "Earth",
    "publication_date": "2020-06-11",
    "active": false
}

THE END LINE OF JSON FORMAT Remove the ==> comma ( , )

Related