Andreas Wahlin wrote:
> I suppose this touches on off topic, but ... is it possible to remove  
> an entry completely from a JSON hash?
>
> say I have
> {
> firstString: 'first',
> secondString: 'second'
> }
>
> and evaluate this into a json object, and I want to remove  
> firstString, could I do something like
> json.remove(json.firstString);
> ?
>   

You could do a regex replace on the "JSON string" before it's eval'd (so 
that the property never gets added to the object);

  e.g.

<script type="text/javascript">
 var jsonStr = "{ firstString: 'first', secondString: 'second', 
thirdString: 'third' }";
 eval("var json = " + jsonStr.replace(/,?\s?secondString:\s?'.*?'/, ''));
        
 if(typeof(json.secondString) == 'undefined')
   alert('worked');
</script>

While this would result in "json" being an object with properties 
"firstString" and "thirdString", it would probably be easier (and not 
reliant on a potentially faulty regEx) to just delete the property from 
the eval'd object via;

delete json.secondString;

~ Brice



_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to