Skip to content

Add is valid json Twig test#4766

Closed
qdequippe wants to merge 4 commits intotwigphp:3.xfrom
qdequippe:json-validate-function
Closed

Add is valid json Twig test#4766
qdequippe wants to merge 4 commits intotwigphp:3.xfrom
qdequippe:json-validate-function

Conversation

@qdequippe
Copy link

@qdequippe qdequippe commented Feb 18, 2026

Add is valid json Twig test using json_validate PHP function

@qdequippe qdequippe force-pushed the json-validate-function branch from dd21e1d to 9f6b0f8 Compare February 18, 2026 10:55
@stof
Copy link
Member

stof commented Feb 18, 2026

What is the use case for having this in Twig templates ?

And this looks like a good candidate for a Twig test instead, exposing an API like value is valid json instead of json_validate(value)

@qdequippe
Copy link
Author

What is the use case for having this in Twig templates ?

My use case is when I want to display http response content, if content is a valid json a CSS class is applied

And this looks like a good candidate for a Twig test instead, exposing an API like value is valid json instead of json_validate(value)

Good point Twig test is a better choice for this, I will update the PR

@stof
Copy link
Member

stof commented Feb 18, 2026

I'm not sure this use case is common enough to ship that in Twig itself. I will let @fabpot give his opinion on this too.

However, this does not prevent registering a Twig test in your own project needing this.

@qdequippe
Copy link
Author

I'm not sure this use case is common enough to ship that in Twig itself. I will let @fabpot give his opinion on this too.

Of course it's just a proposal :)

@qdequippe qdequippe changed the title Add json_validate function Add json_validate test Feb 18, 2026
@qdequippe qdequippe changed the title Add json_validate test Add is valid json Twig test Feb 18, 2026
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this won't accept strings

Co-authored-by: Hugo Alliaume <hugo@alliau.me>
@fabpot
Copy link
Contributor

fabpot commented Feb 18, 2026

I don't think it should be part of core.

@qdequippe qdequippe closed this Feb 18, 2026
@qdequippe qdequippe deleted the json-validate-function branch February 18, 2026 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments