Skip to content

JSON Document Builder

JSON Document Builder takes one or more documents and turns the text of each one into a small JSON object with the key you choose. For example, with the key description, a document whose text is Ergonomic office chair ends up containing {"description":"Ergonomic office chair"}.

It gives texts a key and value structure before passing them on to other components that work with documents.

When to use it

  • You need each text labelled with a field name, for example so a later system knows what it contains.
  • You want to prepare documents in JSON format before splitting or storing them.

Configuration

FieldWhat it does
KeyThe name of the field the JSON object will have, for example description or summary. Always fill it in: it is the name under which the text is stored.
ConnectionWhat to connect
DocumentThe documents whose text you want to convert. It accepts one or several, and only documents (outputs of type Document); outputs of type Data don’t connect here.

Output

Documents returns the converted documents, one for each document received and in the same order. Each one contains only the JSON object with the key and the original text; any additional data the input document had is not kept. You can connect it, for example, to the Input of CharacterTextSplitter.

If something that is not a document reaches Document, the component fails when the flow runs.

Example

A furniture shop wants to store its product descriptions with a clear field name:

  1. Connect the documents with the descriptions to Document.
  2. In Key, type description.
  3. Connect Documents to the component that will process them next.

Each description comes out as {"description":"..."}.

Good practices

  • Use short key names, without spaces or accents, so other systems can read them without trouble.