Skip to content

Instantly share code, notes, and snippets.

@medigor
Created November 23, 2020 08:20
Show Gist options
  • Save medigor/69139294a1911ace69da4d3708119799 to your computer and use it in GitHub Desktop.
Save medigor/69139294a1911ace69da4d3708119799 to your computer and use it in GitHub Desktop.
open System
open System.IO
open System.Text.Json
open System.Threading.Tasks
open FSharp.Control.Tasks.V2
type MyRecord = {
Name: string
Age: int
Id: Guid
}
let writeJson () =
task {
use stream = File.OpenWrite "data.json"
let jwo = JsonWriterOptions(Indented = true)
use writer = new Utf8JsonWriter(stream, jwo)
writer.WriteStartArray()
for i = 1 to 10_000_000 do
let x = {
Name = Guid.NewGuid().ToString()
Age = 99
Id = Guid.NewGuid()}
JsonSerializer.Serialize(writer, x)
if i % 1000 = 0 then
do! writer.FlushAsync()
writer.WriteEndArray()
do! writer.FlushAsync()
}
[<EntryPoint>]
let main argv =
writeJson () |> Task.WaitAll
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment