"Pretty Print" JSON in new framework?

With the new framework, you get the pointer through a property. Data, I think.

Yep, that was it. Cut the time down by about 30%, which is more than I expected.

If I understand it correctly, it’s because the calls on the MemoryBlock are functions whereas the ones on the pointer are operators.

Or I could be making that up.

Can you share the fastest version ?

TIA.

Of course

[code]Function JSONPrettyPrint(JSON As Text) as Text
Const Indent = &h09
Const EndOfLine = &h0A

Dim Bytes() As UInt8
Dim Indents As UInteger

Dim AddAsIs, InQuote As Boolean

Dim Mem As Xojo.Core.MemoryBlock = Xojo.Core.TextEncoding.UTF8.ConvertTextToData(JSON)
Dim Bound As UInteger = Mem.Size - 1
Dim Pointer As Ptr = Mem.Data
For Offset As UInteger = 0 To Bound
Dim Char As UInt8 = Pointer.UInt8(Offset)

If AddAsIs Then
  Bytes.Append(Char)
  AddAsIs = False
ElseIf Char = &h22 Then
  Bytes.Append(Char)
  InQuote = Not InQuote
ElseIf InQuote Then
  Bytes.Append(Char)
  If Char = &h5C Then
    AddAsIs = True
  End If
ElseIf Char = &h7B Or Char = &h5B Then
  Indents = Indents + 1
  Bytes.Append(Char)
  Bytes.Append(EndOfLine)
  For I As UInteger = 1 To Indents
    Bytes.Append(Indent)
  Next
ElseIf Char = &h7D Or Char = &h5D Then
  Indents = Indents - 1
  Bytes.Append(EndOfLine)
  For I As UInteger = 1 To Indents
    Bytes.Append(Indent)
  Next
  Bytes.Append(Char)
ElseIf Char = &h2C Then
  Bytes.Append(Char)
  Bytes.Append(EndOfLine)
  For I As UInteger = 1 To Indents
    Bytes.Append(Indent)
  Next
ElseIf Char = &h3A Then
  Bytes.Append(Char)
  Bytes.Append(&h20)
ElseIf Char = &h0A Or Char = &h0D Or Char = &h20 Or Char = &h09 Then
  // Skip it
Else
  Bytes.Append(Char)
End If

Next

Return Xojo.Core.TextEncoding.UTF8.ConvertDataToText(New Xojo.Core.MemoryBlock(Bytes))
End Function[/code]

Also, I’m updating the answer to this one for future readers. This was still Kem’s solution though.