E07580: must return a JSON

Category: E07xxx Full resolution · Reported in phase: EXPLICIT_TYPE_SYMBOL_DEFINITION · Classification: MUST_RETURN_JSON · All error codes

What went wrong

A function or method is required to return JSON type but returns something else.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 887 (Why must the $$ operator always return JSON in EK9?)

How to fix it

  1. Change return type to JSON

Common causes

  • JSON serialization operator returning wrong type
  • API response type mismatch

See also

  • E07580: JSON return required (this error)
  • E07570: String return required

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E07580: must return a JSON

#!ek9
defines module error.e07580.bad

  defines class

    Label
      text <- "label"

      //'$$' converts to JSON
      default operator ?

      operator $$ as pure
        <- rtn as String: text

Fixed: Return JSON

#!ek9
defines module error.e07580.good

  defines class

    Label
      text <- "label"

      default operator ?

      operator $$ as pure
        <- rtn as JSON: JSON("text", JSON(text))

Questions and answers

These Q&A entries show E07580 and its fix: