Repository F# setup
open Reified
open Reified.Refinements
open Reified.ResultWhat Data represents
Data represents structured values with six cases. The model maps directly to JSON and also works for fixtures,
configuration, command-line input, form values, events, and other tree-shaped data.
Data.render uses a compact display with unquoted ordinary field names and JSON quoting and escaping for text. For scalars it reads the same as JSON output; for Data.Object it does not, since JSON
requires quoted field names and Data.render does not produce them. Use Data.Json.render when the result must be
valid JSON. See Render for people.
type Data =
| Null
| Text of string
| Number of token: string
| Bool of bool
| List of Data list
| Object of (string * Data) list
FsLiveDocsGeneratedPage1_9A5DDEA924C8.DataNullTextstringAn abbreviation for the CLI type . Basic Types
Numbertoken: stringBoolboolAn abbreviation for the CLI type . Basic Types
ListlistThe type of immutable singly-linked lists. See the module for further operations related to lists. Use the constructors [] and :: (infix) to create values of this type, or the notation [1; 2; 3]. Use the values in the List module to manipulate values of this type, or pattern match against the values directly. See also F# Language Guide - Lists.
ObjectData.Null
Null is a present value with no scalar content.
open Reified
Data.render Data.Null
// => "null"
ReifiedReified.DataModulerender: Data -> stringRenders structured data in a compact, human-readable form. Data.render (data [ "name" => "Ada"; "active" => true ]) // { name: "Ada", active: true }
Reified.DataA portable tree for structured data. Data preserves null, text, number, Boolean, list, and object distinctions without depending on a serializer or input format. Data is a structured-value model, not a source syntax tree. It does not model whitespace, comments, source locations, or other format-specific syntax. Number values currently retain a lexical token so adapters do not narrow arbitrary-size integers, decimal precision, or exponent notation to one runtime numeric type.
NullA null value.
Requires & types
Requires: open Reified (packages: Reified.Data)A null field is different from an absent field. In literal syntax, "value" => nil includes a null field, while
"value" ?=> None omits the field.
Data.Text
Text stores a .NET string and renders it as a quoted string with the required escaping.
Data.render (Data.Text "Ada\nLovelace")
// => "\"Ada\\nLovelace\""
Reified.DataModulerender: Data -> stringRenders structured data in a compact, human-readable form. Data.render (data [ "name" => "Ada"; "active" => true ]) // { name: "Ada", active: true }
Reified.DataA portable tree for structured data. Data preserves null, text, number, Boolean, list, and object distinctions without depending on a serializer or input format. Data is a structured-value model, not a source syntax tree. It does not model whitespace, comments, source locations, or other format-specific syntax. Number values currently retain a lexical token so adapters do not narrow arbitrary-size integers, decimal precision, or exponent notation to one runtime numeric type.
TextA text value.
Requires & types
Requires: open Reified (packages: Reified.Data)A null .NET string converts to Data.Null; it does not become Data.Text null.
Data.Number
Number stores the number as a token rather than converting every number to one CLR numeric type. This retains
large integers, decimal precision, trailing zeros, and exponent notation.
Data.render (Data.Number "1.2300e+4")
// => "1.2300e+4"
Reified.DataModulerender: Data -> stringRenders structured data in a compact, human-readable form. Data.render (data [ "name" => "Ada"; "active" => true ]) // { name: "Ada", active: true }
Reified.DataA portable tree for structured data. Data preserves null, text, number, Boolean, list, and object distinctions without depending on a serializer or input format. Data is a structured-value model, not a source syntax tree. It does not model whitespace, comments, source locations, or other format-specific syntax. Number values currently retain a lexical token so adapters do not narrow arbitrary-size integers, decimal precision, or exponent notation to one runtime numeric type.
NumberA number whose portable lexical token avoids narrowing it to one runtime numeric type.
Requires & types
Requires: open Reified (packages: Reified.Data)render reproduces the token without reformatting. The token is
visible to exact comparison: 1, 1.0, and 1e0 are different. Use the num function rather than the
union case when accepting text, because num checks that the token is a valid JSON number.
The Number union case does not validate its token, so Data.Number "not a number" constructs a value directly.
Data.render and Data.Json.render both emit the token verbatim; for an invalid token that produces output that is
not valid JSON. Always go through Data.number/Data.num, or the JSON parser, when the token came from input you
did not already validate.
See Numbers for conversion rules and examples.
Data.Bool
Bool stores true or false.
Data.render (Data.Bool true)
// => "true"
Reified.DataModulerender: Data -> stringRenders structured data in a compact, human-readable form. Data.render (data [ "name" => "Ada"; "active" => true ]) // { name: "Ada", active: true }
Reified.DataA portable tree for structured data. Data preserves null, text, number, Boolean, list, and object distinctions without depending on a serializer or input format. Data is a structured-value model, not a source syntax tree. It does not model whitespace, comments, source locations, or other format-specific syntax. Number values currently retain a lexical token so adapters do not narrow arbitrary-size integers, decimal precision, or exponent notation to one runtime numeric type.
BoolA Boolean value.
Requires & types
Requires: open Reified (packages: Reified.Data)Data.List
List stores ordered Data values. Order and repeated values are preserved.
Data.render (Data.List [ Data.Text "author"; Data.Text "admin" ])
// => "[\"author\", \"admin\"]"
Reified.DataModulerender: Data -> stringRenders structured data in a compact, human-readable form. Data.render (data [ "name" => "Ada"; "active" => true ]) // { name: "Ada", active: true }
Reified.DataA portable tree for structured data. Data preserves null, text, number, Boolean, list, and object distinctions without depending on a serializer or input format. Data is a structured-value model, not a source syntax tree. It does not model whitespace, comments, source locations, or other format-specific syntax. Number values currently retain a lexical token so adapters do not narrow arbitrary-size integers, decimal precision, or exponent notation to one runtime numeric type.
ListAn ordered collection of structured values.
TextA text value.
Requires & types
Requires: open Reified (packages: Reified.Data)Exact comparison checks every item and its position. Matching can instead check an ordered subsequence, an unordered subset, every item, or at least one item.
Data.Object
Object stores an ordered list of name/value pairs. It preserves declaration order and duplicate field names.
let value =
Data.Object [
"name", Data.Text "Ada"
"name", Data.Text "Grace"
]
Data.render value
// => "{ name: \"Ada\", name: \"Grace\" }"
value: DataReified.DataA portable tree for structured data. Data preserves null, text, number, Boolean, list, and object distinctions without depending on a serializer or input format. Data is a structured-value model, not a source syntax tree. It does not model whitespace, comments, source locations, or other format-specific syntax. Number values currently retain a lexical token so adapters do not narrow arbitrary-size integers, decimal precision, or exponent notation to one runtime numeric type.
ObjectAn ordered collection of named structured values.
TextA text value.
Reified.DataModulerender: Data -> stringRenders structured data in a compact, human-readable form. Data.render (data [ "name" => "Ada"; "active" => true ]) // { name: "Ada", active: true }
Requires & types
Requires: open Reified (packages: Reified.Data)val value: DataPath lookup and edits select the last field when a name is repeated. Exact comparison observes every field, including duplicates and order. Partial object matching consumes matching duplicate fields one occurrence at a time.
open Reified.DataDSL
let repeated =
Data.Object [
"name", Data.Text "Ada"
"name", Data.Text "Grace"
]
Data.lookupPath "name" repeated
// => Data.Text "Grace" — a path inspects the last occurrence
Data.tryMatch [ at "" (containing [ "name" => "Ada" ]) ] repeated
// => Ok () — containing matches the first occurrence, consuming it
ReifiedReified.DataDSLConcise opt-in syntax for literals, immutable edits, cases, and matching.
repeated: DataReified.DataA portable tree for structured data. Data preserves null, text, number, Boolean, list, and object distinctions without depending on a serializer or input format. Data is a structured-value model, not a source syntax tree. It does not model whitespace, comments, source locations, or other format-specific syntax. Number values currently retain a lexical token so adapters do not narrow arbitrary-size integers, decimal precision, or exponent notation to one runtime numeric type.
ObjectAn ordered collection of named structured values.
TextA text value.
Reified.DataModulelookupPath: string -> Data -> DataParses a path and finds its value or returns Null.
tryMatch: DataExpectation list -> Data -> Result<unit,DataMismatch list>Checks path-based expectations and accumulates structured mismatches. Data.tryMatch [ at "name" "Ada" ] (data [ "name" => "Grace" ]) // Error [ mismatch at path "name": expected "Ada", found "Grace" ]
at: string -> ^a -> DataExpectationRequires a path to contain an exact value or recursive pattern.
containing: DataField list -> DataPatternCreates a partial object pattern from required fields. Data.tryMatch [ at "" (containing [ "id" => 42 ]) ] (data [ "id" => 42; "extra" => true ]) // Ok ()
(=>): string -> ^value -> DataFieldAssociates a field name with an exact value or recursive data pattern.
Requires & types
Requires: open Reified; open Reified.DataDSL (packages: Reified.Data)val repeated: DataPaths
Fields and list items are addressed by a separate path type. DataPath identifies nested fields and zero-based list indexes. String paths use dots for ordinary field names,
brackets for indexes, and quoted brackets for names containing punctuation.
DataPath.parse "customer.roles[1]"
// => [ DataPathSegment.Name "customer"; DataPathSegment.Name "roles"; DataPathSegment.Index 1 ]
DataPath.parse "metadata[\"build.version\"]"
// => [ DataPathSegment.Name "metadata"; DataPathSegment.Name "build.version" ]
Reified.DataPathModuleHelpers for constructing, parsing, and rendering structured data paths.
parse: string -> DataPathParses a structured data path or raises when the text is invalid.
Requires & types
Requires: open Reified (packages: Reified.Data)The empty path "" addresses the root value.