Recent

Author Topic: [SOLVED] SynEdit JSON  (Read 2506 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
[SOLVED] SynEdit JSON
« on: July 26, 2020, 11:28:03 pm »
Hi All,

Can SynEdit be used to format and high the following text, for example :
Quote
{"status_code":7,"status_message":"Invalid API key: You must be granted a valid key.","success":false}

If so how?

Thanks in advance.
« Last Edit: July 27, 2020, 04:15:42 pm by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12199
  • Debugger - SynEdit - and more
    • wiki
Re: SynEdit JSON
« Reply #1 on: July 26, 2020, 11:48:44 pm »
I do not know, if there currently is a json highlighter (I don't think I've seen one). But if not there is a tutorial on the wiki how to write a highlighter.

About formatting: SynEdit does not change the format of a text. So it will not nicely wrap and indent the text.
You would need your own formatting code.

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: SynEdit JSON
« Reply #2 on: July 27, 2020, 08:21:23 am »
OK. I found a JSON beautifier

https://www.example-code.com/delphiDll/json_pretty_print.asp

But the result doesn't display correctly in SynEdit, in a Memo it's OK.

There seems to be a problem with CR+LF. See attachment.

Does SynEdit handle these differently?

How can I control it?

Thanks.
« Last Edit: July 27, 2020, 09:39:14 am by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

varianus

  • New Member
  • *
  • Posts: 27
Re: SynEdit JSON
« Reply #3 on: July 27, 2020, 08:26:26 am »
Some time ago i've found and adapted a json highlighter for synedit, you can find it here: https://github.com/varianus/ovotext/blob/master/highlighters/synhighlighterjson.pas.

On this unit https://github.com/varianus/ovotext/blob/master/supportfuncs.pas you can find a quite working FormatJson function.

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: SynEdit JSON
« Reply #4 on: July 27, 2020, 09:05:40 am »
I'm not sure what to do with these files  :(
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

paweld

  • Hero Member
  • *****
  • Posts: 1572
Re: SynEdit JSON
« Reply #5 on: July 27, 2020, 11:56:48 am »
Formatting json:
Code: Pascal  [Select][+][-]
  1. uses
  2.   fpjson, jsonparser, jsonscanner;
  3.  
  4. procedure TForm1.Button1Click(Sender: TObject);
  5. var
  6.   jpar: TJSONParser;
  7. begin
  8.   jpar:=TJSONParser.Create(MemoSrc.Lines.Text, [joUTF8]);
  9.   MemoDest.Lines.Text := jpar.Parse.FormatJSON([], 2);  
  10.   jpar.Free;
  11. end;
Best regards / Pozdrawiam
paweld

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: SynEdit JSON
« Reply #6 on: July 27, 2020, 12:43:46 pm »
Thanks
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Edson

  • Hero Member
  • *****
  • Posts: 1327
Re: [SOLVED] SynEdit JSON
« Reply #7 on: July 27, 2020, 04:17:58 pm »
To create a custom SynEdit Highlighter, exists SynFacilSyn: https://github.com/t-edson/SynFacilSyn
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

 

TinyPortal © 2005-2018