diff --git a/src/FSharp.Data.Json.Core/JsonValue.fs b/src/FSharp.Data.Json.Core/JsonValue.fs index e028641c5..e55625859 100644 --- a/src/FSharp.Data.Json.Core/JsonValue.fs +++ b/src/FSharp.Data.Json.Core/JsonValue.fs @@ -37,12 +37,19 @@ type JsonSaveOptions = [] [] type JsonValue = + /// A JSON string value | String of string + /// A JSON number stored as a decimal (used for numbers that fit in the decimal range) | Number of decimal + /// A JSON number stored as a float (used for large numbers that do not fit in decimal) | Float of float + /// A JSON object, represented as an array of name-value pairs | Record of properties: (string * JsonValue)[] + /// A JSON array of values | Array of elements: JsonValue[] + /// A JSON boolean value | Boolean of bool + /// A JSON null value | Null /// @@ -59,7 +66,10 @@ type JsonValue = else str - /// Serializes the JsonValue to the specified System.IO.TextWriter. + /// Serializes the JsonValue to the specified System.IO.TextWriter. + /// The writer to serialize to. + /// Controls formatting: indented, compact, or compact with spaces. + /// Number of spaces per indentation level (default 2). Only used when saveOptions is . member x.WriteTo(w: TextWriter, saveOptions, ?indentationSpaces: int) = let indentationSpaces = defaultArg indentationSpaces 2 @@ -179,11 +189,18 @@ type JsonValue = if lastWritePos < value.Length then w.Write(value.Substring(lastWritePos)) + /// Serializes this JsonValue to a string with the specified formatting options. + /// Controls formatting: indented, compact, or compact with spaces. + /// Number of spaces per indentation level (default 2). Only used when saveOptions is . + /// The JSON string representation. member x.ToString(saveOptions, ?indentationSpaces: int) = let w = new StringWriter(CultureInfo.InvariantCulture) x.WriteTo(w, saveOptions, ?indentationSpaces = indentationSpaces) w.GetStringBuilder().ToString() + /// Serializes this JsonValue to a formatted (indented) string. + /// Number of spaces per indentation level (default 2). + /// The formatted JSON string representation. member x.ToString(?indentationSpaces: int) = x.ToString(JsonSaveOptions.None, ?indentationSpaces = indentationSpaces) @@ -482,28 +499,39 @@ type private JsonParser(jsonText: string) = type JsonValue with - /// Parses the specified JSON string + /// Parses the specified JSON string. + /// The JSON string to parse. + /// A representing the parsed JSON. static member Parse(text) = JsonParser(text).Parse() - /// Attempts to parse the specified JSON string + /// Attempts to parse the specified JSON string. + /// The JSON string to parse. + /// Some if parsing succeeds, or None if parsing fails. static member TryParse(text) = try Some <| JsonParser(text).Parse() with _ -> None - /// Loads JSON from the specified stream + /// Loads JSON from the specified stream. + /// The stream to read JSON from. + /// A representing the parsed JSON. static member Load(stream: Stream) = use reader = new StreamReader(stream) let text = reader.ReadToEnd() JsonParser(text).Parse() - /// Loads JSON from the specified reader + /// Loads JSON from the specified reader. + /// The text reader to read JSON from. + /// A representing the parsed JSON. static member Load(reader: TextReader) = let text = reader.ReadToEnd() JsonParser(text).Parse() - /// Loads JSON from the specified uri asynchronously + /// Loads JSON from the specified URI asynchronously. + /// The URI to load JSON from (file path or URL). + /// The text encoding to use (default: UTF-8). + /// An async computation yielding a representing the parsed JSON. static member AsyncLoad(uri: string, [] ?encoding) = async { let encoding = defaultArg encoding Encoding.UTF8 @@ -512,11 +540,16 @@ type JsonValue with return JsonParser(text).Parse() } - /// Loads JSON from the specified uri + /// Loads JSON from the specified URI. + /// The URI to load JSON from (file path or URL). + /// The text encoding to use (default: UTF-8). + /// A representing the parsed JSON. static member Load(uri: string, [] ?encoding) = JsonValue.AsyncLoad(uri, ?encoding = encoding) |> Async.RunSynchronously - /// Parses the specified string into multiple JSON values + /// Parses the specified string into multiple JSON values (e.g. newline-delimited JSON). + /// The string containing multiple JSON values. + /// A sequence of instances. static member ParseMultiple(text) = JsonParser(text).ParseMultiple() member private x.PrepareRequest(httpMethod, headers) = @@ -535,12 +568,20 @@ type JsonValue with TextRequest(x.ToString(JsonSaveOptions.DisableFormatting)), headers, httpMethod - /// Sends the JSON to the specified URL synchronously. Defaults to a POST request. + /// Sends the JSON to the specified URL synchronously. Defaults to a POST request. + /// The URL to send the JSON to. + /// The HTTP method to use (default: POST). + /// Additional HTTP headers to include. + /// An containing the server's response. member x.Request(url: string, [] ?httpMethod, [] ?headers: seq<_>) = let body, headers, httpMethod = x.PrepareRequest(httpMethod, headers) Http.Request(url, body = body, headers = headers, httpMethod = httpMethod) - /// Sends the JSON to the specified URL asynchronously. Defaults to a POST request. + /// Sends the JSON to the specified URL asynchronously. Defaults to a POST request. + /// The URL to send the JSON to. + /// The HTTP method to use (default: POST). + /// Additional HTTP headers to include. + /// An async computation yielding an containing the server's response. member x.RequestAsync(url: string, [] ?httpMethod, [] ?headers: seq<_>) = let body, headers, httpMethod = x.PrepareRequest(httpMethod, headers) Http.AsyncRequest(url, body = body, headers = headers, httpMethod = httpMethod)