shas
shas

Reputation: 703

how to replace or update json value in file?

file contains json format like this

    {
    "ClusterName": {
        "Description": "Name of the dbX Cluster",
        "Type": "String",
        "MinLength": "1",
        "MaxLength": "64",
        "AllowedPattern": "[-_ a-zA-Z0-9]*",
        "Default": "my-cluster_wait_timimg",
        "ConstraintDescription": "can contain only alphanumeric characters, spaces, dashes and underscores."
    }
}

I want to read file and display "my-cluster_wait_timimg". after that, how do update above value using html tag .

<input type=text id="" value=""/> 

Upvotes: 0

Views: 337

Answers (1)

shas
shas

Reputation: 703

Got answer and this working fine for me.

<!DOCTYPE html>
<html>
<body>

<h2>Create Object from JSON String</h2>

<input type="text" id="demo">
<button onclick="fun1()">Click here</button>

<script>
var text = '{"ClusterName":{        "Description": "Name of the dbX Cluster",        "Type": "String",        "MinLength": "1",        "MaxLength": "64",        "AllowedPattern": "[-_ a-zA-Z0-9]*","Default": "my-cluster_wait_timimg",        "ConstraintDescription": "can contain only alphanumeric characters, spaces, dashes and underscores."}}';

obj = JSON.parse(text);
document.getElementById("demo").value =
obj.ClusterName.Default + " " ;

function fun1() {
var rs=document.getElementById("demo").value;
alert(rs);
}
</script>

</body>
</html>

Upvotes: 1

Related Questions