Skip to content

Instantly share code, notes, and snippets.

@PaulGreenwell
Created September 25, 2013 04:23
Show Gist options
  • Save PaulGreenwell/6695143 to your computer and use it in GitHub Desktop.
Save PaulGreenwell/6695143 to your computer and use it in GitHub Desktop.
VB.Net extension class that serialises and object to JSON
Imports System.IO
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Converters
Imports System.Runtime.CompilerServices
Public Module JsonExtensions
<Extension()>
Public Function ToJson(ByVal entity As Object) As String
Dim serializer = New JsonSerializer()
serializer.Converters.Add(New StringEnumConverter())
Using writer As New StringWriter()
serializer.Serialize(writer, entity)
Return writer.ToString()
End Using
End Function
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment