<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Path Dependent &#187; json</title>
	<atom:link href="http://pathdependent.com/tag/json/feed/" rel="self" type="application/rss+xml" />
	<link>http://pathdependent.com</link>
	<description>Programming, Complex Systems, Trading, and Introspection</description>
	<lastBuildDate>Tue, 20 Jul 2010 23:09:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JSON as a Universal DB Model DSL</title>
		<link>http://pathdependent.com/2009/12/30/json-as-a-universal-db-model-dsl/</link>
		<comments>http://pathdependent.com/2009/12/30/json-as-a-universal-db-model-dsl/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 15:20:25 +0000</pubDate>
		<dc:creator>John Nelson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://pathdependent.com/?p=402</guid>
		<description><![CDATA[I write web applications rarely and reluctantly. I am not the most qualified to initiate a project based on the following ideas. If I did, it would likely  fall into a state of disrepair once my ephemeral attention has shifted back to playing with stock prices. However, I think it is a good idea. I [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fpathdependent.com%2F2009%2F12%2F30%2Fjson-as-a-universal-db-model-dsl%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fpathdependent.com%2F2009%2F12%2F30%2Fjson-as-a-universal-db-model-dsl%2F" height="61" width="51" /></a></div><p>I write web applications rarely and reluctantly. I am not the most qualified to initiate a project based on the following ideas. If I did, it would likely  fall into a state of disrepair once my ephemeral attention has shifted back to <a href="http://pathdependent.com/2009/10/29/perpetual_motion/">playing with stock prices</a>. However, I think it is a good idea. I am hoping someone who has both the time and interest codes it up. This is a new level of lazy.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> user_model <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>
    <span style="color: #006600; font-style: italic;">// column name , generalized type,   , validation rule,   hidden?</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'first_name'</span>  <span style="color: #339933;">,</span> <span style="color: #3366CC;">'text'</span>              <span style="color: #339933;">,</span> <span style="color: #3366CC;">'name_regex'</span>              <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'last_name'</span>   <span style="color: #339933;">,</span> <span style="color: #3366CC;">'text'</span>              <span style="color: #339933;">,</span> <span style="color: #3366CC;">'name_regex'</span>              <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'middle_name'</span> <span style="color: #339933;">,</span> <span style="color: #3366CC;">'text'</span>              <span style="color: #339933;">,</span> <span style="color: #3366CC;">'name_regex'</span>              <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'birth_date'</span>  <span style="color: #339933;">,</span> <span style="color: #3366CC;">'date'</span>              <span style="color: #339933;">,</span> <span style="color: #3366CC;">'over_18'</span>                 <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'location'</span>    <span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'double'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'double'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">,</span> undefined<span style="color: #339933;">,</span>        <span style="color: #339933;">,</span>   <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'addresses'</span><span style="color: #339933;">,</span>  <span style="color: #339933;">,</span> <span style="color: #3366CC;">'has_many'</span>          <span style="color: #339933;">,</span>                           <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Basically, from a Rails perspective, replace your ruby database migration DSL with code that parses the above JSON (e.g. user_model.json) and creates the appropriate schema. Replace your ActiveRecord validations with the validations from the json model. (Depending on your language, there may be differences in REGEX syntax. Having some well defined common REGEX definitions, such as EMAIL_VALIDATION, might be appropriate.) On the client side, you can display most forms automagically, based on the order defined in the json model (if it is in fact an array.) Furthermore, you can also run client side validations before submission. (If your validations are so weak that sharing them remotely represents a security risk, you are probably doing something wrong.) It might also remove the need for many controllers. A lot of CRUD is so generic that it might be possible to have a single /:model/:action/* controller. Scaffolding is not DRY. Finally, as the lingua franca, sharing model definitions outside your project&#8217;s language is simplified.</p>
<p>Any takers?</p>
]]></content:encoded>
			<wfw:commentRss>http://pathdependent.com/2009/12/30/json-as-a-universal-db-model-dsl/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
