We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How to stop JSON tags being parsed as EE tags?

Development and Programming

Kyle Slattery's avatar
Kyle Slattery
109 posts
15 years ago
Kyle Slattery's avatar Kyle Slattery

Hi all,

I’m trying to create a plugin that outputs JSON, however, since JSON looks like EE tags, they’re being parsed. For instance, if my plugin outputs this:

[{title: "hello", body: "body"},{title: "Hello2", body: "body2"}]

The rendered template ends up looking like this, because it interprets the {} parts as tags:

[,]

How can I get EE to not parse this section? I feel there’s probably some super simple way around this, but I just haven’t found it.

-Kyle

       
Kyle Slattery's avatar
Kyle Slattery
109 posts
15 years ago
Kyle Slattery's avatar Kyle Slattery

Oh, forgot to note, this is for 1.6.x.

       
ender's avatar
ender
1,644 posts
15 years ago
ender's avatar ender

change the format so that the closing brackets are on a different line from the opening brackets.

[
    {
        title: "hello", 
        body: "body"
    },
    {
        title: "Hello2", 
        body: "body2"
    }
]
       
Kyle Slattery's avatar
Kyle Slattery
109 posts
15 years ago
Kyle Slattery's avatar Kyle Slattery
change the format so that the closing brackets are on a different line from the opening brackets.

Thanks for the reply. Unfortunately, the way I’m currently doing it is using PHP’s json_encode(), so I don’t really have any control over how it’s outputted. I guess I could switch to generating it myself, but if there’s a way to work around it using json_encode(), that’d be best.

-Kyle

       
ender's avatar
ender
1,644 posts
15 years ago
ender's avatar ender

just pass the string given to you by json_encode through a str_replace(“}”, “\n}”, $json) function call. note that the naive approach here will probably mess up any data that happens to have curly braces in it, but it’s a start and maybe you know your data won’t have any.

       
Kyle Slattery's avatar
Kyle Slattery
109 posts
15 years ago
Kyle Slattery's avatar Kyle Slattery

Ah, good call, I’ll give that a try.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.