GenerateJson Wyam.Json

Converts objects stored in metadata or elsewhere to JSON.
Generates JSON for a specified object (which can come from document metadata or elsewhere) and stores it as new content for each input document or in each document's metadata.

Package

This module exists in the Wyam.Json package which is not part of the core distribution. Add the following preprocessor directive to your configuration file to use it:
#n Wyam.Json

Usage

  • GenerateJson(ContextConfig data, string destinationKey = null)

    The object returned by the specified delegate is converted to JSON, which then either replaces the content of each input document or is stored in the specified metadata key.

    • data

      A delegate that returns the object to convert to JSON.

    • destinationKey

      The metadata key where the JSON should be stored (or null to replace the content of each input document).

  • GenerateJson(DocumentConfig data, string destinationKey = null)

    The object returned by the specified delegate is converted to JSON, which then either replaces the content of each input document or is stored in the specified metadata key.

    • data

      A delegate that returns the object to convert to JSON.

    • destinationKey

      The metadata key where the JSON should be stored (or null to replace the content of each input document).

  • GenerateJson(IEnumerable<string> keys, string destinationKey = null)

    Allows you to specify metadata keys for each input document that should be serialized as properties in a JSON object.

    • keys

      The metadata keys to serialize as properties.

    • destinationKey

      The metadata key where the JSON should be stored (or null to replace the content of each input document).

  • GenerateJson(string sourceKey, string destinationKey = null)

    The object stored in metadata at the specified key is converted to JSON, which then either replaces the content of each input document or is stored in the specified metadata key.

    • sourceKey

      The metadata key of the object to convert to JSON.

    • destinationKey

      The metadata key where the JSON should be stored (or null to replace the content of each input document).

Fluent Methods

Chain these methods together after the constructor to modify behavior.

  • WithCamelCase(bool camelCase = true)

    Specifies whether the generated JSON should use a camel case naming strategy for property names. The default behavior is not to generate camel case property names.

    • camelCase

      If set to true, camel case property names are generated.

  • WithIndenting(bool indenting = true)

    Specifies whether the generated JSON should be indented.

    • indenting

      If set to true, the JSON is indented.

  • WithSettings(Action<JsonSerializerSettings> settings)

    Allows changing the JSON serializer settings.

    • settings

      An action that manipulates the serializer settings.

GitHub