Skip to content

msgspec.ValidationError: Expected 'object', got 'null' #800

@akatsukiHell

Description

@akatsukiHell

Question

Hello, everyone. I'm parsed dynamic JSON from HTML and try to parse this part, trying get number from 'song' children in 'songPage' parent using msgspec but get the error:
msgspec.ValidationError: Expected 'object', got 'null' - at '$.songPage[...]'

Python code

from msgspec.json import decode
from msgspec import Struct

data = re.search(
            r'window\.__PRELOADED_STATE__ = JSON\.parse\(\'(.*)\'\)', req
      ).group(1).replace("\\\\\\\"", '\'').replace("\\","")

class songID(Struct):
      song: int

class songData(Struct):
      songPage: dict[str, songID]

song_id = decode(data, type=songData)

JSON

{
"currentPage": "songPage",
   "songPage": {
       "longTailCacheExperiment": null,
       "song": 10584710,
       "pinnedQuestions": [],
       "metadataQuestions": [
           "producer:song:10584710",
           "release-date:song:10584710",
           "writer:song:10584710"
}

I looked at Conda Repodata in docs but don't understand how to can skip this 'null' part in the first line of children.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions