SharePoint: what does JSON error message mean

vrm 711 Reputation points
2023-09-19T10:46:45.11+00:00

Using an online JSON validator, I was informed that my code has the following error:

Error: Parse error on line 10:
...eld-fontSizeSmall'"}
----------------------^
Expecting ':', got '}'

My JSON code

 { 	"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json", 	"additionalEventClass": {
		"operator": "==",
 		"operands": [
 			"[$Activity]",
 			"Conference or Event"
 		]
 	},
 	"=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgRed' , 'sp-css-backgroundColor-BgRed sp-css-color-WhiteFont')+' sp-field-fontSizeSmall'"
 }

Microsoft 365 and Office SharePoint For business Windows
{count} votes

4 answers

Sort by: Most helpful
  1. vrm 711 Reputation points
    2023-09-22T10:01:50.5433333+00:00

    The code to display one colored coded activity in a view:

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
      "additionalEventClass": {
        "operator": ":",
        "operands": [
          {
            "operator": "==",
            "operands": [
              "[$Activity]",
              "Conference or Event"
            ]
          },
          "=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgRed' , 'sp-css-backgroundColor-BgRed sp-css-color-WhiteFont')+' sp-field-fontSizeSmall'",
          ""
        ]
      }
    }
    
    1 person found this answer helpful.

  2. Vanessa 356 Reputation points
    2023-09-25T10:40:43.9133333+00:00

    I wanted the code for the individual views to be as simple as possible. The following is an example of what worked for me:

    {   "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",   "additionalEventClass": {     "operator": ":",     "operands": [       {         "operator": "==",         "operands": [           "[$Activity]",           "Conference or Event"         ]       },       "=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgRed' , 'sp-css-backgroundColor-BgRed sp-css-color-WhiteFont')+' sp-field-fontSizeSmall'",       ""     ]   } }
    
    0 comments No comments

  3. Ling Zhou_MSFT 23,620 Reputation points Microsoft External Staff
    2023-09-21T09:04:20.13+00:00

    Hi @vrm,

    Apologize for the late reply.

    Please select your calendar view -> format current view->Advanced mode.

    User's image

    Please copy the JSON below:

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/calendar-formatting.schema.json",
      "additionalEventClass": "=if([$Activity] =='Blog Post' && @isSelected == true,'sp-css-color-WhiteFont sp-css-backgroundColor-BgGreen sp-css-backgroundColor-BgGreen sp-css-color-WhiteFont ',if([$Activity] =='Campaign Push' && @isSelected == true,'sp-css-color-BlackFont sp-css-backgroundColor-BgCoral sp-css-backgroundColor-BgCoral sp-css-color-BlackFont',if([$Activity] =='Conference or Event' && @isSelected == true,'sp-css-color-WhiteFont sp-css-backgroundColor-BgRed sp-css-backgroundColor-BgRed sp-css-color-WhiteFont',if([$Activity] =='MIR Release' && @isSelected == true,'sp-css-color-WhiteFont sp-css-backgroundColor-BgDarkRed sp-css-backgroundColor-BgDarkRed sp-css-color-WhiteFont',if([$Activity] =='Newsletter Blast' && @isSelected == true,'sp-css-color-WhiteFont sp-css-backgroundColor-BgGray sp-css-backgroundColor-BgGray sp-css-color-WhiteFont',if([$Activity] =='Observance Day' && @isSelected == true,'sp-css-color-WhiteFont sp-css-backgroundColor-BgOrange sp-css-backgroundColor-BgOrange sp-css-color-WhiteFont',if([$Activity] =='Paid Media Run' && @isSelected == true,'sp-css-color-BlackFont sp-css-backgroundColor-BgSage sp-css-backgroundColor-BgSage sp-css-color-BlackFont',if([$Activity] =='Social Post' && @isSelected == true,'sp-css-color-WhiteFont sp-css-backgroundColor-BgTeal sp-css-backgroundColor-BgTeal sp-css-color-WhiteFont',if([$Activity] =='Video Release' && @isSelected == true,'sp-css-color-BlackFont sp-css-backgroundColor-BgGold sp-css-backgroundColor-BgGold sp-css-color-BlackFont',if([$Activity] =='Podcast Episode' && @isSelected == true,'sp-css-color-WhiteFont sp-css-backgroundColor-BgPurple sp-css-backgroundColor-BgPurple sp-css-color-WhiteFont','')))))))))) + 'sp-field-fontSizeSmall'"
    }
    

    enter image description here

    Also, I have a couple of clarifications:

    1. I checked the JSON you provided, where operator and operands are syntax from SharePoint2019 JSON formatting, which is not available for SharePoint Online.

    2.For Calendar view JSON formatting, you should use "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/calendar-formatting.schema. json" instead of "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json".

    For more SharePoint Online views on JSON formatting, you can check out these articles: SharePoint Online view formatting.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  4. Ling Zhou_MSFT 23,620 Reputation points Microsoft External Staff
    2023-09-22T03:01:29.0066667+00:00

    Hi @vrm,

    I apologize that I may have misunderstood your needs. Let me confirm with you that your requirement is that you want the text and background color to be modified when the corresponding time is selected. Please correct me if I misunderstood.

    Unselected:

    User's image

    Selected:

    User's image

    If I understand correctly, you can try replacing the JSON below:

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
      "additionalEventClass": {
        "operator": ":",
        "operands": [
          {
            "operator": "==",
            "operands": [
              "[$Activity]",
              "Blog Post"
            ]
          },
          "=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgGreen' , '')+' sp-field-fontSizeSmall'",
          {
            "operator": ":",
            "operands": [
              {
                "operator": "==",
                "operands": [
                  "[$Activity]",
                  "Campaign Push"
                ]
              },
              "=if(@isSelected == true, 'sp-css-color-BlackFont sp-css-backgroundColor-BgCoral' , '')+' sp-field-fontSizeSmall'",
              {
                "operator": ":",
                "operands": [
                  {
                    "operator": "==",
                    "operands": [
                      "[$Activity]",
                      "Conference or Event"
                    ]
                  },
                  "=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgRed' , '')+' sp-field-fontSizeSmall'",
                  {
                    "operator": ":",
                    "operands": [
                      {
                        "operator": "==",
                        "operands": [
                          "[$Activity]",
                          "MIR Release"
                        ]
                      },
                      "=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgDarkRed' , '')+' sp-field-fontSizeSmall'",
                      {
                        "operator": ":",
                        "operands": [
                          {
                            "operator": "==",
                            "operands": [
                              "[$Activity]",
                              "Newsletter Blast"
                            ]
                          },
                          "=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgGray' , '')+' sp-field-fontSizeSmall'",
                          {
                            "operator": ":",
                            "operands": [
                              {
                                "operator": "==",
                                "operands": [
                                  "[$Activity]",
                                  "Observance Day"
                                ]
                              },
                              "=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgOrange' , '')+' sp-field-fontSizeSmall'",
                              {
                                "operator": ":",
                                "operands": [
                                  {
                                    "operator": "==",
                                    "operands": [
                                      "[$Activity]",
                                      "Paid Media Run"
                                    ]
                                  },
                                  "=if(@isSelected == true, 'sp-css-color-BlackFont sp-css-backgroundColor-BgSage' , '')+' sp-field-fontSizeSmall'",
                                  {
                                    "operator": ":",
                                    "operands": [
                                      {
                                        "operator": "==",
                                        "operands": [
                                          "[$Activity]",
                                          "Podcast Episode"
                                        ]
                                      },
                                      "=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgPurple' , '')+' sp-field-fontSizeSmall'",
                                      {
                                        "operator": ":",
                                        "operands": [
                                          {
                                            "operator": "==",
                                            "operands": [
                                              "[$Activity]",
                                              "Social Post"
                                            ]
                                          },
                                          "=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgTeal' , '')+' sp-field-fontSizeSmall'",
                                          {
                                            "operator": ":",
                                            "operands": [
                                              {
                                                "operator": "==",
                                                "operands": [
                                                  "[$Activity]",
                                                  "Video Release"
                                                ]
                                              },
                                              "=if(@isSelected == true, 'sp-css-color-BlackFont sp-css-backgroundColor-BgGold' , '')+' sp-field-fontSizeSmall'",
                                              ""
                                            ]
                                          }
                                        ]
                                      }
                                    ]
                                  }
                                ]
                              }
                            ]
                          }
                        ]
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    }
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.