Skip to content

Conversation

@tors42
Copy link
Contributor

@tors42 tors42 commented Feb 22, 2024

Here is a suggestion of a restructuring of the JSON response of the the broadcast PGN push endpoint,
https://lichess.org/api#tag/Broadcasts/operation/broadcastPush

It changes from JSON array of name:value objects,
to a single keys:values object.

Oh, as I'm writing this Pull Request, I realize that the original format might have the benefit of keeping a desired order of the tags... Well, opening the Pull Request anyways - in case order isn't important... 🤔

Before
{
  "games": [
    {
      "tags": [
        {
          "White": "Rasmus Svane"
        },
        {
          "WhiteElo": "2632"
        },
        {
          "WhiteTitle": "GM"
        },
        {
          "WhiteTeam": "Germany"
        },
        {
          "Black": "Rajat Makkar"
        },
        {
          "BlackElo": "2453"
        },
        {
          "BlackTitle": "FM"
        },
        {
          "BlackTeam": "France"
        },
        {
          "Result": "1-0"
        }
      ],
      "moves": 2
    },
    {
      "tags": [
        {
          "White": "Joseph Girel"
        },
        {
          "WhiteElo": "2484"
        },
        {
          "WhiteTitle": "IM"
        },
        {
          "WhiteTeam": "France"
        },
        {
          "Black": "Matthias Bluebaum"
        },
        {
          "BlackElo": "2658"
        },
        {
          "BlackTitle": "GM"
        },
        {
          "BlackTeam": "Germany"
        },
        {
          "Result": "0-1"
        }
      ],
      "moves": 2
    }
  ]
}
After
{
  "games": [
    {
      "tags": {
        "White": "Rasmus Svane",
        "Black": "Rajat Makkar",
        "BlackElo": "2453",
        "BlackTeam": "France",
        "BlackTitle": "FM",
        "WhiteTeam": "Germany",
        "Result": "1-0",
        "WhiteElo": "2632",
        "WhiteTitle": "GM"
      },
      "moves": 2
    },
    {
      "tags": {
        "White": "Joseph Girel",
        "Black": "Matthias Bluebaum",
        "BlackElo": "2658",
        "BlackTeam": "Germany",
        "BlackTitle": "GM",
        "WhiteTeam": "France",
        "Result": "0-1",
        "WhiteElo": "2484",
        "WhiteTitle": "IM"
      },
      "moves": 2
    }
  ]
}

Change from JSON array of name:value objects,
to a single keys:values object

Before:
  "tags": [
    {
      "White": "Rasmus Svane"
    },
    {
      "Black": "Rajat Makkar"
    }
  ]

After:
  "tags": {
    "White": "Rasmus Svane",
    "Black": "Rajat Makkar"
  }
@fitztrev
Copy link
Member

I wondered about that too. Though another benefit of the current format is if there are duplicate tags. Whether duplicate tags should happen though, I don't know.

@ornicar ornicar merged commit 743da51 into lichess-org:master Feb 23, 2024
@tors42 tors42 deleted the push-pgn-response-json-format branch February 23, 2024 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants