Forum Discussion
JSON Error When Making No Changes
Trying to learn JSON so I can do some fun stuff with values coloring of lists.
I currently have a calculated column with:
=IF([Starting Date]="","",[Starting Date]+21)
and that works fine.
When I go to format the columns in Advanced mode, I'm always getting errors, sometimes without even changing anything. The error is not clear and I don't what I'm doing or not doing.
For example, leaving it like this:
- RobElliottSilver Contributor
xoxidein "For example, leaving it like this:..." you can't do that because the JSON is not doing anything, all you've got is the schema so it will inevitably give you an error. What you need is JSON like this which is formatting the Workdays+21 column:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json", "elmType": "div", "txtContent": "@currentField", "style": { "padding-left": "14px", "background-color": "=if(@currentField <= @now, '#c00000','teal')", "color": "white" } }
That gives the following result:
Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)- xoxideinIron ContributorI'm clearly missing something. I copied your code over mine, and it changes it to teal, but I get the error:
Error saving column format: {"d": {"CustomFormatter": "{\"$schema\":\"https:\u002F\u002Fdeveloper.microsoft.com\u002Fjson-schemas\u002Fsp\u002Fv2\u002Fcolumn-formatting.schema.json\",\"elmType\":\"div\",\"txtContent\":\"@currentField\",\"style\":{\"color\":\"white\",\"background-color\":\"=if(toLocaleDateString(@currentField+1296000000) <= toLocaleDateString(@now), 'green', if(toLocaleDateString(@currentField+604800000) <= toLocaleDateString(@now) , 'orange', 'red'))\"}}", "Id": ""}}
Could it be because this is a calculated column? The value (which is a date) is based on another date field plus 21 days.- RobElliott's solution worked for me. To be sure there isn't something else going on, change the view formatter to design mode and select alternating rows. Save it and make sure it works.
If that works, either edit from there, or compare with what you have to see if you can figure out what is tripping you up. Usually, the editor catches if something is wrong, but it's not perfect.
If it doesn't work, try it on a different list and see if you can duplicate the issue.
- flibbertCopper Contributor
xoxidein I see the same problem with a colleague trying to save/update a piece of JSON that she's copying in that we know works - since it works if I do it. I'm guessing it has something to do with encoding (in a desktop editor I've had such problems with say Unicode) - but then I noticed that my colleague was using Edge where I always use Chrome.
She switched to Chrome and the code saved without error!