Stof Docs
Star on GitHubStof WebsiteDiscordContact Us
  • 🚀Welcome
  • ℹ️Resources & Information
  • Book
    • Data Interface
    • Introduction & Design
    • Host Environments
      • Rust
      • TypeScript
        • Extend Stof
        • Import Statement
    • Data Interchange
      • JSON to Stof
      • Importing and Parsing Data
      • Exporting Data
      • REST and Restructure
    • Configuration Files
    • Schemas
      • Renaming Fields
      • Removing Fields
      • Validation & Transformation
        • Example Access
      • Nested Schemas
    • Orchestration
  • Common Concepts
    • Objects
    • Primitive Types
    • Functions
    • Fields
    • Object Types
    • Imports
    • Error Handling
    • Units
    • Casting/Conversions
  • Reference
    • CLI
      • 🏃Run
      • 🧪Test
      • 📚CLI Libraries
        • Filesystem Library
        • Time Library
        • HTTP Library
    • Stof Language
    • Libraries
      • Standard Library
      • Array/Vector Library
      • Number Library
      • String Library
      • Object Library
      • Function Library
      • Set Library
      • Map Library
      • Data Library
      • Tuple Library
      • Blob Library
      • Boolean Library
    • 🪧Formats
Powered by GitBook
On this page

Was this helpful?

  1. Book
  2. Data Interchange

Exporting Data

Targeting systems that do not understand Stof (yet).

PreviousImporting and Parsing DataNextREST and Restructure

Last updated 3 months ago

Was this helpful?

Just like a lot of data is not defined as Stof, a lot of systems are unaware of Stof, but aware of some other form of data.

Stof export data just as easily as they import data!

In this example, we'll import some data, mutate it a little, and then export it in another standard interchange format.

This simulates receiving data (either from a file, API, etc.), parsing it into a Stof interface as an interchange transform step, and then exporting it to a binary stream or string to use in another API call. The same transform step would be valid in preparing this document to be used directly by an application, however, we are demonstrating the "stringify" and "blobify" functions found in the .

import "./record.toml" as Record; // creates a new root named "Record"

#[main]
fn main() {
    Record.renameField("resourceType", "type");
    drop Record.active;
    for (name in Record.name) {
        name.renameField("family", "last");
        name.renameField("use", "purpose");
    }

    let binary = blobify(Record, "json"); // Uint8Array or Vec<u8>
    parse(binary, "json", "self.Clone");  // parse the binary into location "self.Clone"

    let json = stringify(Record, "json");
    assertEq(json, stringify(self.Clone, "json"));

    pln(stringify(Record, "toml")); // lots of formats to choose from... or add your own!
}

Make sure to install the and use the "run" command to test this function.

> stof run ./example.stof
id = "example"
type = "Patient"

[[name]]
given = ["Peter", "James"]
last = "Chalmers"
purpose = "official"

[[name]]
given = ["Jim"]
purpose = "usual"

[[name]]
given = ["Peter", "James"]
last = "Windsor"
purpose = "maiden"

[name.period]
end = "2002"
active = true
id = "example"
resourceType = "Patient"

[[name]]
family = "Chalmers"
given = ["Peter", "James"]
use = "official"

[[name]]
given = ["Jim"]
use = "usual"

[[name]]
family = "Windsor"
given = ["Peter", "James"]
use = "maiden"

[name.period]
end = "2002"

Take a look at the and the for more information on the "renameField" function and "drop" statement used in this example.

formats
Standard Library
Stof CLI
Object Library
Stof Language Reference