Metreeca MIME
    Preparing search index...

    Function json

    • Creates a JSON parser.

      The task converts a feed of JSON documents into a feed of values, one value per document, so that downstream tasks work on structured data rather than on text.

      Each document is given either as text or as a response carrying it in its body. Empty or whitespace-only documents produce no value, and neither do responses without a body.

      Response bodies are always decoded as UTF-8, the only encoding JSON is exchanged in. Invalid UTF-8 bytes are read as replacement characters.

      A response is logged as a warning, and parsed anyway, if its content type is not a JSON one or its charset is not UTF-8. JSON content types are application/json and +json formats such as application/ld+json.

      Note

      • Incremental: each value is emitted as soon as its document is parsed, so endless sources are processed for as long as the feed is consumed.
      • Materialising: each document is held in memory as a whole while it is parsed, so peak memory use is about twice the size of the largest document, regardless of the length of the feed.
      • Stateless: each document is parsed independently, so the result doesn't depend on how the feed is split across nested feeds or runs.
      Warning

      Malformed documents are skipped and logged as warnings, and the feed runs to completion.

      Type Parameters

      • V extends Value = Object

        The type of the values produced; parsed documents are emitted as is and are not validated against it; defaults to a JSON Object

      Returns Task<string | Response, V>

      A task converting a feed of JSON documents, given as text or as responses, into a feed of values

      Error While the feed is consumed, if the source feed fails or a response body can't be read