Undocumented 'to_json' Modifier in Movable Type 5 for Direct JSON-format Output

| 18 Comments | No TrackBacks |
This Japanese blog post alerted me to the existence of an undocumented 'to_json' modifier in Movable Type 5.  There is a well documented list of global modifiers like encode_html, trim, capitalize... available here, but 'to_json' seems to be missing from that list or any other place in the documentation.  What does it do?
JSON (JavaScript Object Notation) is a popular data format that is used by many applications to store/transmit/receive hierarchically organised information, like the properties of a list of items.  The 'to_json' attribute in Movable Type lets you output data stored in array and hash variables directly in JSON format, without the need for additional loop tags or template code.  

Consider this snippet of template code:

<mt:setvarblock name="item{color}">blue</mt:setvarblock>
<mt:setvarblock name="item{id}">5</mt:setvarblock>
<mt:setvarblock name="item{status}">OK</mt:setvarblock>

<mt:var name="item" to_json="1">

This will result in:

{"color":"blue","status":"OK","id":"5"}

Or with a simple array:

<mt:var name="items[0]" value="zero">
<mt:var name="items[1]" value="one">
<mt:var name="items[2]" value="two">
<mt:var name="items[3]" value="three">

<mt:var name="items" to_json="1">

Which results in:

["zero","one","two","three"]

It even works recursively:

<mt:setvarblock name="item{color}">blue</mt:setvarblock>
<mt:setvarblock name="item{id}">5</mt:setvarblock>
<mt:setvarblock name="item{status}">OK</mt:setvarblock>

<mt:var name="items{first}" value="$item">

<mt:setvarblock name="item{color}">red</mt:setvarblock>
<mt:setvarblock name="item{id}">7</mt:setvarblock>
<mt:setvarblock name="item{status}">INACTIVE</mt:setvarblock>

<mt:var name="items{second}" value="$item">

<mt:var name="items" to_json="1">

This results in:

{"first":{"color":"blue","status":"OK","id":"5"},"second":{"color":"red","status":"INACTIVE","id":"7"}}

Neat!  I'm sure this will come in handy if you ever need to export large amounts of data from Movable Type in JSON format...


No TrackBacks

TrackBack URL: https://www.movabletips.com/cgi-bin/mt/mt-tb.cgi/2018

18 Comments

Thanks for the tip, Maarten. For more on how to use the JSON in a MT template, I'd recommend the following article:

http://thecomposingstick.com/2010/03/using-jquery-with-movable-type.html

Excellent post. Keep writing such kijnd of information on your blog.
Im really impressed by your blog.
Hello there, You have performed a fantastic job.
I'll certainly digg it and in my opinion suggest to my friends.
I'm sure they'll be benefited from this site.

Hello mates, itts great post regarding educationand entirely explained, keep
it up all the time.

It's really a great and helpful piece of information.
I am satisfied that you simply shared this useful info with us.
Please stay us up to date like this. Thank you for sharing.

It doesnt involve any masking oor chemicals which
is what making this engraving method popular.
3D laser engraving is a relatively new form of graphic art that is growing
in popularity in many industries. A trophy iss 'evidence' tat that person has dobe their best and achieved something special.
Images of landmarks, like the Eiffel tower or the Taj
Mahal, are populasr souvenir items and create
a lifelog remembrance of that special holiday. For the reason that designate tungste carbide will be lengthy, a lott of jewelers,
among them Larson Jewelry retailers, simply use the thoujght
of "tungsten"to elucidate tungsten carbide companies.
As per the need of the operator, you can also make the
required changes.

It doesnt involve any masking oor chemicals which
is what making this engraving method popular.
3D laser engraving is a relatively new form of graphic art that is growing
in popularity in many industries. A trophy iss 'evidence' tat that person has dobe their best and achieved something special.
Images of landmarks, like the Eiffel tower or the Taj
Mahal, are populasr souvenir items and create
a lifelog remembrance of that special holiday. For the reason that designate tungste carbide will be lengthy, a lott of jewelers,
among them Larson Jewelry retailers, simply use the thoujght
of "tungsten"to elucidate tungsten carbide companies.
As per the need of the operator, you can also make the
required changes.

No matter howw small your budget is, make sure never to compromise quality over quantity.

When designing a stamp for yojr business, use the tips above to help.
Preview your custkm rubber sttamp by finding the show me
my stamp button to view tthe aappearance of you stamp, there should also be an option to downloa a PDF of this as well.

Just be patient keep alternating the use of the tape and the toothpick numerous times.

The unfavorable oof the artwork and polymer sachet is sandwiched between twoo sheets of glass spaced
2-3mm apart which can be then exposed in the machine to get a couple of minutes.

The first-time, stamp it on plain white cardstock with plain black
ink. Disadvantages - High capitazl investment, maintenance expenses and running will probably be a lot in exccess
of vulcanizing or polymer approaches of manufacture.
First and foremost, assess why youu will need to print on darker paper.

Regardless off if youu are planning on opening your own
engraving machine business or just someone who would like to learn the art of engraving, the
finished product will speak for itself. For instance, a university can engrave
their beloved mascot running down the football field onto a glass trophy that iis handed oout to alll graduates.
Business owners aand companies also do go for laser engraving.

This technology was created by a group of sleep-deprived
students at Brown University in partnership with some of the
country's most prestigious sleep doctors and scientists.
' Here are some on my favorites I hzve created hyperlinks (as any good technophile would)'.

Article Source: youu arre searching for high quality promotional products and items for marketing,
business, and advertising purposes, tke
a look at. These items are so popular among customers due
to the fact that tyey can be used over and over again,
possibly even every day. Your budget can help you decide what to
use for promottional item and the varieties available
within it. You can put them in a boxx and transport them to your event or
to your company's office building. If that message or
call to action gets lost in the translation, however, effectiveness can be challenged.
Most probably, because career women are sure of themselves.

That is a good tip particularly to those fresh tto the blogosphere.
Simple but very precise information… Thanks for sharing thiks one.
A must read post!

Negative production has been simplified with the introduction of water based negative technology, photographic chemicals for producing negatives are now a thing of
the past. Heat and pressure is applied to the master plate
and matrix board inside a Vulcanizing press. Take the item of clothing you wish to put your fully customised and unique to
you rubber stamp impression on and stamp, yes it is that easy.
The unmounted rubber stamp dies produced with any of these manufacturing methods
can be cut up and affixed to simple hand stamps, dater stamps
or self inking stamps. More than 210,000 people are
victims of trafficking each year.

Hello to every single one, it's really a nice for me to visit
this web page, it contains important Information.

The ink resists until around the 10th wash at 90 to 60,
following on from this it is recommended that the wash temperature is
reduced to a maximum of 40;. The small notary printers by Xstamper are used
through out the USA and abroad and are a very popular choice.
Select your chosen design template from the options that are available
and add the text that you require. There are several different types
available, self inking stamps re-ink automatically after each impression using a built in ink pad.
These days a lot of science and research has been invested
to produce the modern plastic self inking stamps.

Take some time out and work out what it is you want and howw you can create for yourself in the next chapter of your life.
Thesee previously mentioned suggestions are simply
that, suggestions. It's not ok to point fingers at someone else, especially if you are at fault.
People would cry and release old programming while working with a horse of their choice.
If you need motivation to get the job done, how about rewarding yourself for each fifteen minute session.

If you want more exercise in your life, you
must make promises and create systems and accountabilities, in the area of exercise.

Many states also require speech-language pathologists to
hold a Certificate of Clinical Competence in Speech-Language
Pathology (CCC-SLP) offered by the American Speech-Language-Hearing Association.

The International Coach Federation ( is considered the leading professional coaching organization.
I hope these tips help in your baseball handicapping. If you need motivation
to get the job done, how about rewarding yourself for each fifteen minute session.

All these people turned to unemployment, many of them laughing
all the way to the bank. Employee coaching provides an alternative supplement to
formal training. 'In addition to their size,
the strength, their athleticism and their flexibility, I also look at the intangible,'Klenakis said.

Look for job opportunities with established coaches and coaching firms.
t have the persistence, patience and are not goal-oriented, you can forget it.

They have remaining center at http://www.midencelawfirm.com//cheap-nfl-jerseys-wholesale-5187818.html 15 or sometimes cheap youth nfl jerseys 16 your wholesale http://www.sbefabrication.com/sites/louis-vuitton-outlet-280468.html authentic jerseys lack of employment cheap authentic nfl jerseys china monthly premiums nike nfl football jerseys analysts www.chuckharvey.com/cheapjaguarsjersey.html is just about http://www.nerdpop.com/ch http://www.christianfaithinternational.com/images/louis-vuitton-outlet-1563082.html e

Leave a comment