We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Syntax colours for JSON

Thread ID:

Created:

Updated:

Platform:

Replies:

130235 Apr 30,2017 07:46 PM May 15,2017 11:44 AM WPF 3
loading
Tags: EditControl
Richard
Asked On April 30, 2017 07:46 PM

Could the EditControl be used to display JSON files? I see how it works for XML but not sure whether it could handle JSON?

Venkateshwaran Ramdoss [Syncfusion]
Replied On May 1, 2017 06:59 AM

Hi Richard, 
 
Thank you for contacting Syncfusion Support. 
 
Yes. EditControl is working for JSON file. We have prepared for a sample by using custom language for your reference. Please make use of the below code example. 
 
Code example[XAML] 
 
  <syncfusion:FormatsCollection x:Key="JSONLanguageFormats"> 
                <syncfusion:EditFormats Foreground="Black" FormatName="OperatorFormat"/> 
                <syncfusion:EditFormats Foreground="Blue" FormatName="LiteralsFormat"/> 
  </syncfusion:FormatsCollection> 
 
  <syncfusion:LexemCollection x:Key="JSONLanguageLexems">                                
                <syncfusion:Lexem StartText="&quot;" EndText="&quot;" IsMultiline="False" LexemType="Literals" FormatName="LiteralsFormat"/>                 
                <syncfusion:Lexem StartText=":" ContainsEndText="False" IsMultiline="False" LexemType="Operator" FormatName="OperatorFormat"/> 
  </syncfusion:LexemCollection> 
 
We have prepared a sample and screenshot for your reference and it can be downloaded from the below link. 
 
 
Screenshot 
 
 
 
 
Please refer the below documentation link for more details. 
 
 
Please check the above solution and let me us know if it is helpful. 
 
Regards, 
Venkateshwaran V.R. 


Richard
Replied On May 8, 2017 11:54 AM

Thanks for the assistance, this is really helpful...

Is there any way the formatting can cater for the following...

In JSON you frequently gget lines like  

"literal1": "literal2"

In this case, literal1 and literal2 should be in different colours, as per the image below




thanks for  your help

Venkateshwaran Ramdoss [Syncfusion]
Replied On May 15, 2017 11:44 AM

Hi Richard, 
 
Thank you for your update.  
 
At present, there is no direct support available for your requirement. We have tried to achieve your requirement using Custom Language support. Please make use of the below code example. 
 
Code example[C#] 
 
new Lexem { StartText = @"(?<=([\'\""]))(?=:)", IsRegex=true, IsMultiline = false, ContainsEndText = false, LexemType = EditTokenType.Keyword, FormatName= "AfterColon" }, 
 
We have prepared a sample for your reference and it can be downloaded from the below link. 
 
 
Screenshot 
 
 
 
Please check the above solution and let us know if it is helpful. 
 
Regards, 
Venkateshwaran V.R. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;