Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JSON viewers don't accept my pattern even after dict going through json.dumps() + json.loads()

The result when printing after a = json.dumps(dicter) and print(json.loads(a)) is this:

{
  '10432981': {
    'tournament': {
      'name': 'Club Friendly Games',
      'slug': 'club-friendly-games',
      'category': {
        'name': 'World',
        'slug': 'world',
        'sport': {
          'name': 'Football',
          'slug': 'football',
          'id': 1
        },
        'id': 1468,
        'flag': 'international'
      },
      'uniqueTournament': {
        'name': 'Club Friendly Games',
        'slug': 'club-friendly-games',
        'category': {
          'name': 'World',
          'slug': 'world',
          'sport': {
            'name': 'Football',
            'slug': 'football',
            'id': 1
          },
          'id': 1468,
          'flag': 'international'
        },
        'userCount': 0,
        'hasPositionGraph': False,
        'id': 853,
        'hasEventPlayerStatistics': False,
        'displayInverseHomeAwayTeams': False
      },
      'priority': 0,
      'id': 86
    }
  }
}

But when trying to read in any json viewer, they warn that the format is incorrect but don’t specify where the problem is.

If it doesn’t generate any error when converting the dict to JSON and not even when reading it, why do views warn of failure?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You must enclose the strings using double quotes ("). The json.loads returns a python dictionary, so it is not a valid JSON object. If you want to get valid JSON you can get the string that json.dumps returns.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading