Issue with Parsing JSON Response in Custom Code

Hey all, another quick question (effect-http related).

I have this code snippet for fetching some data from a public API:

const getArtist = Http.request
  .get("https://musicbrainz.org/ws/2/artist/?query=ac%5C%2Fdc&fmt=json")
  .pipe(
    Http.client.fetch,
    Effect.andThen(Http.response.schemaBodyJson(SearchResult)),
    Effect.catchTag("ParseError", (e) =>
      Effect.fail(ServerError.internalServerError(e))
    ),
    Effect.tap(Console.log),
    Effect.scoped
  );


I ensured that the URL returns a correct JSON object, as I tested it in Insomnia.

SearchResult is simply a Schema.Struct:

export const SearchResult = s.Struct({
  created: s.String,
  count: s.Number,
  offset: s.Number,
  artists: s.Array(ArtistS),
});


Where ArtistS is a big type/Struct containing all the data returned from the API. The result in general conforms to what is returned from the API.

However, for some reason, I seem to get this error:

{"_id":"ParseError","message":"{ created: string; count: number; offset: number; artists: ReadonlyArray<{ id: string; type: string; type-id: string; score: number; name: string; sort-name: string; country: string; disambiguation: string; area: { id: string; type: string; type-id: string; name: string; sort-name: string; life-span: { ended?: boolean | undefined } }; begin-area: { id: string; type: string; type-id: string; name: string; sort-name: string; life-span: { ended?: boolean | undefined } }; ipis: ReadonlyArray<string>; isnis: ReadonlyArray<string>; life-span: { begin: string; ended?: boolean | undefined }; aliases: ReadonlyArray<{ sort-name: string; type-id: string; name: string; type: string; locale?: string | undefined; primary?: boolean | undefined; begin-date?: string | undefined; end-date?: string | undefined }>; tags: ReadonlyArray<{ count: number; name: string }> }> }\n└─ [\"created\"]\n   └─ is missing"}


I'm not sure why it's saying created is missing; Insomnia showed it to be correct. That leads me to believe I'm not doing something right with the fetch? I'm just not sure exactly what at present.
Was this page helpful?