public static Object FromJsValue(this JsValue val)
            switch (val.Type)
                case Types.Boolean:
                    return val.AsBoolean();
                case Types.Number:
                    return val.AsNumber();
                case Types.String:
                    return val.AsString();
                case Types.Object:
                    var obj = val.AsObject();
                    var node = obj as DomNodeInstance;

                    if (node != null)
                        return node.Value;

                    return obj;
                case Types.Undefined:
                    return "undefined";
                case Types.Null:
                    return null;

            return val.ToObject();
Example #2
        public static object Uncast(this JsValue value)
            if (value.IsBoolean()) {
                return value.AsBoolean();
            if (value.IsNumber()) {
                return value.AsNumber();
            if (value.IsObject()) {
                return value.AsObject();
            if (value.IsString()) {
                return value.AsString();

            return null;
 /// <summary>
 /// Gets a named value from an object.
 /// </summary>
 /// <param name="value">
 /// The object to check (though the type is IJsonValue so multiple
 /// calls to Get can be chained together).
 /// </param>
 /// <param name="name">The name of the value to lookup.</param>
 /// <returns>
 /// The value associated with the name, or null if the instance isn't
 /// an object or the name was not found.
 /// </returns>
 public static IJsonValue Get(this IJsonValue value, string name)
     JsonObject obj = value.AsObject();
     IJsonValue val = null;
     if (obj != null)
         obj.TryGetValue(name, out val);
     return val;