Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Navigate to Workbench. The ad-hoc pipeline editor opens.

  2. Replace the existing content by this pipeline:

    Code Block
    languageyaml
    pipeline:
      - drive.read:
          path: "person.json"
  3. RUN the pipeline and you should see the content of the file person.json as output:

    Code Block
    languagejson
    {
      "firstName": "Marissa",
      "lastName": "Smith",
      "age": 33
    }

    This is because the file is automatically converted from a content object to its the mime type format - which is JSON in this case - and then sent to the client.

  4. In order to “see” the content object and not the result, change the pipeline to this:

    Code Block
    languageyaml
    pipeline:
      - drive.read:
          path: "person.json"
      - set.body:
          value: "#{@convert.toJson(body)}"
  5. RUN the pipeline and you should see as output the content object with meta information about the file:

    Code Block
    languagejson
    {
    	"name": "person.json",
    	"created": 1637045518731,
    	"lastUpdated": null,
    	"size": 64,
    	"data": "ewogICJmaXJzdE5hbWUiOiAiTWFyaXNzYSIs...",
    	"mimeType": "application/json"
    }

...

In case you want to work with the JSON data of a file, the data part of the content object is the interesting thing for you. In order to load this into the body, again use the @convert.toJson() but this time point to the data property:

Code Block
languageyaml
pipeline:
  - drive.read:
      path: "person.json"
  - set.body:
      value: "#{@convert.toJson(body.data)}"

...

You should see an output similar to this, which transformed the JSON:

Code Block
languagetext
"Full name: Marissa Smith"

...