How do i get typeof of json values like string or number or Boolean or null

{
	"connectors": [{
		"SCHEMA_TABLE_NAME": "SC_MSSL_375",
		"NO_OF_COLUMNS": 2,
		"SOURCE_CONNECTION_ID": 3,
		"LASTSCHEDULEDON": null,
		"CLIENT_ID": 0,
		"LICENSE_REQUIRED": "0",
		"DATASET_ID": "3ad92fbb-a3a7-4cf6-a562-91836695b582",
		"CONNECTOR_ID": 20,
		"NAME": "11 demo large 2",
		"DATA_TABLE_NAME": "DS_MSSL_375",
		"SCHEDULE_TABLE_NAME": "SH_MSSL_375",
		"CONNECTOR_LOGO_L": "small_logos/logos/sqlserver.png",
		"CONNECTOR_LOGO_S": "/sqlserver.png",
		"JOB_STATUS": "Successful",
		"CATEGORY": "Database",
		"CREATEDON": 1473568076000,
		"ROW_ID": 375,
		"LASTRUNON": 1473568076000,
		"NO_OF_ROWS": 16450,
		"DESTINATION_CONNECTION_ID": 3,
		"LAST_UPDATED_ON": 1473568076000,
		"DESCRIPTION": "11",
		"SCHEDULE_CRON": null,
		"CONNECTORNAME": "MSSQL",
		"CREATED_BY": "zp861"
	}, {
		"SCHEMA_TABLE_NAME": "SC_MSSL_362",
		"NO_OF_COLUMNS": 1,
		"SOURCE_CONNECTION_ID": 3,
		"LASTSCHEDULEDON": null,
		"CLIENT_ID": 0,
		"LICENSE_REQUIRED": "0",
		"DATASET_ID": "14da9f02-271b-4a03-b50a-9d30d1109a18",
		"CONNECTOR_ID": 20,
		"NAME": "test error",
		"DATA_TABLE_NAME": "DS_MSSL_362",
		"SCHEDULE_TABLE_NAME": "SH_MSSL_362",
		"CONNECTOR_LOGO_L": "small_logos/logos/sqlserver.png",
		"CONNECTOR_LOGO_S": "/sqlserver.png",
		"JOB_STATUS": "Failed",
		"CATEGORY": "Database",
		"CREATEDON": 1473464152000,
		"ROW_ID": 362,
		"LASTRUNON": 1473467021000,
		"NO_OF_ROWS": null,
		"DESTINATION_CONNECTION_ID": 3,
		"LAST_UPDATED_ON": 1473464152000,
		"DESCRIPTION": "error",
		"SCHEDULE_CRON": null,
		"CONNECTORNAME": "MSSQL",
		"CREATED_BY": "zp861"
	}]
}

You can use the typeof operator to find out what the type is.
A working example using your code can be seen at https://jsfiddle.net/a0swzj1L/1/
where I assigned the json values to a variable called response, and then did:

var result = document.querySelector("#result");
result.innerHTML += "response.connectors is an " + typeof response.connectors + "<br>";
result.innerHTML += "response.connectors is an array? " + Array.isArray(response.connectors) + "<br>";
result.innerHTML += "response.connectors[0].SCHEMA_TABLE_NAME is a " + typeof response.connectors[0].SCHEMA_TABLE_NAME + "<br>";
result.innerHTML += "response.connectors[0].NO_OF_COLUMNS is a " + typeof response.connectors[0].NO_OF_COLUMNS + "<br>";
result.innerHTML += "response.connectors[1].LASTSCHEDULEDON is a " + typeof response.connectors[1].LASTSCHEDULEDON + "<br>";
result.innerHTML += "response.connectors[1].CREATEDON is a " + typeof response.connectors[1].CREATEDON + "<br>";

which gives:

response.connectors is an object
response.connectors is an array? true
response.connectors[0].SCHEMA_TABLE_NAME is a string
response.connectors[0].NO_OF_COLUMNS is a number
response.connectors[1].LASTSCHEDULEDON is a object
response.connectors[1].CREATEDON is a number
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.