Extend JSON language definition to support template placeholders

In Our project we have custom JSONs that contain placeholders which will be replaced with concrete values. This works fine with string values but e.g. for numbers the JSON is considered invalid:
{
“intValue”: ${FILL-IN:someIntValue}
}

I was able to create a custom language definition and use a LanguageSubstitutor to use my language for the files (which match a certain file name). I also (with some AI help) was able to create a TemplateJsonLexerAdapter which detects these occurences.

By I cannot get the file to be evaluated like a regular JSON apart from these placeholders. I’ve overwritten com.intellij.json.JsonParserDefinition#createElement to return a custom ASTWrapperPsiElement which implements JsonValue but that doesn’t seem to work.
com.intellij.psi.impl.source.tree.CompositeElement#createPsiNoLock detecs that the element type of the tokens is JSON.

I’m not even sure if this is the right approach. What would be easiest way to achieve this? I “only” want that the placeholders are not considered errors and code formatting still works. I wrote a complete custom language plugin once but that seems to be overkill. I think it would suffice if things like ${FILL-IN:some.value} would be treated as a string.

Thank you.

Please take a look at Template languages APIs and implement a template language instead.

Good example is Handlebars plugin:

See com.dmarcotte.handlebars.file.HbFileViewProvider

Template languages can be combined with any data language of your choice including JSON without modifying them.

I doubt you can extend JSON the way you need