Thursday, May 30, 2013

Re: Importing data using loaddata from exported data using dumpdata

Bill,

These are the exact steps I follow:

python manage.py dumpdata --indent=4 > fixtures/data.json

python manage.py loaddata fixtures/data.json

That is when I get:

DeserializationError: No JSON object could be decoded

I checked the json code using http://jsonlint.com/ and it was reported as being valid. (The json code is reproduced at the end of this post for your info)

I openned the file using Notepad++, copied it all into regular Notepad.exe and then saved it as a new json file. When I do the loaddata command with that new file it works just fine.

When I copy paste the code from Notepad.exe back into a new file on Notepad++ and save that, the resultant file works just fine as well.

This link: http://stackoverflow.com/questions/8732799/django-fixtures-jsondecodeerror suggested that the unicode text file needed to be converted to ascii. It was also pointed out that the file in a hexeditor should start with 5B and not any other byte. Sure enough, in the hexeditor, the file straight from the dump began with FF FE, but the notepad saved json file began with 5B. Could it be my setup that is at fault producing the wrong json file dump?

[
    {
        "pk": 1, 
        "model": "books.publisher", 
        "fields": {
            "state_province": "MA", 
            "city": "Cambdridge", 
            "name": "O'Reilly Media", 
            "country": "USA", 
            "website": "www.oreilly.com", 
            "address": "73 Prince Street"
        }
    }, 
{
        "pk": 2, 
        "model": "books.publisher", 
        "fields": {
            "state_province": "CA", 
            "city": "Bakersfield", 
            "name": "Randomn House", 
            "country": "USA", 
            "website": "www.randomn.com", 
            "address": "234 Hollywood Boulevard"
        }
    }, 
{
        "pk": 3, 
        "model": "books.publisher", 
        "fields": {
            "state_province": "NY", 
            "city": "New York", 
            "name": "Pearson Vue", 
            "country": "USA", 
            "website": "www.pearson.com", 
            "address": "1 Wall Street"
        }
    }, 
    {
        "pk": 1, 
        "model": "books.author", 
        "fields": {
            "first_name": "Eric", 
            "last_name": "Meyer", 
            "email": ""
        }
    }, 
    {
        "pk": 2, 
        "model": "books.author", 
        "fields": {
            "first_name": "Seth", 
            "last_name": "Meyer", 
            "email": ""
        }
    }, 
        {
        "pk": 3, 
        "model": "books.author", 
        "fields": {
            "first_name": "Vincent", 
            "last_name": "Meyer", 
            "email": ""
        }
    }, 
{
        "pk": 1, 
        "model": "books.book", 
        "fields": {
            "publisher": 1, 
            "authors": [
                1
            ], 
            "isbn": 123456789, 
            "publication_date": null, 
            "title": "CSS: The Definitive Guide"
        }
    },
    {
        "pk": 2, 
        "model": "books.book", 
        "fields": {
            "publisher": 3, 
            "authors": [
                2
            ], 
            "isbn": 987654321, 
            "publication_date": null, 
            "title": "Primer on Banking"
        }
    },
   {
        "pk": 3, 
        "model": "books.book", 
        "fields": {
            "publisher": 2, 
            "authors": [
                1,2
            ], 
            "isbn": 543216789, 
            "publication_date": null, 
            "title": "Frolicking on the Beach"
        }
    }
]

On Sunday, March 4, 2012 12:04:08 AM UTC+3, Vincent Bastos wrote:
Hi,

I am having trouble importing data using loaddata from a .json file that I created from a dumpdata export. I have a production application which runs MySQL on one server and a development machine which runs SQLite. I simple executed ./manage.py dumpdata > file.json on the production machine, but when I execute ./manage.py loaddata file.json I get the error:

ValueError: No JSON object could be decoded

I would appreciate some sort of trouble shooting direction, as I could not find anything that would help me in the docs.

Cheers

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment