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

Time:07-14

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?

CodePudding user response:

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.

  • Related