---
title: "Determine if single value or sub array JSON"  
description: "Determine if single value or sub array JSON"  
author: "Anonymous User"  
published: 2013-05-10  
updated: 2013-05-10  
canonical: https://www.mindstick.com/forum/861/determine-if-single-value-or-sub-array-json  
category: "json"  
tags: ["json"]  
reading_time: 2 minutes  

---

# Determine if single value or sub array JSON

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances)!\
I have an [algorithm](https://www.mindstick.com/blog/119/implementing-cryptography-in-c-sharp-dot-net-by-using-sha1-algorithm) which binds an object from MVC (C#) to the view. The key and the data can be anything, this is up to the implementer.\
The issue that I am having is that I cannot [determine if](https://www.mindstick.com/forum/158797/create-a-rust-program-to-determine-if-a-number-is-prime-or-not) something in the JSON string is an array or a simple string. The following code works recursively. If it is \
an array, it needs to dig deeper. Otherwise, it will bind the value it found based on the key and value.\
[function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) constructView(data){ for(var key in data) { if (data[key].length > 1) { var count = 0;\
while (count < data.length) { constructView(data[count]); count++; } } $("#" + key).html(data[key]); }}This is just a [prototype](https://www.mindstick.com/news/2386/every-detail-regarding-twitter-leak-of-xiaomi-outfolding-smartphone-prototype), so at the moment it does not generate [components](https://www.mindstick.com/blog/74096/understanding-the-role-of-some-integral-ac-components) but simply does bindings.\
Ok, so, the issue:\
When I pass in\
{"data":"this is a [response](https://www.mindstick.com/forum/12719/how-to-make-response-write-display-special-character-like-lt-gt)","[strings](https://www.mindstick.com/forum/161912/explain-the-python-strings)":["test1","test2"]}\
It returns 18 and 2 for lengths. This is because both are technically arrays with a valid length.\
Is there a way to get a item length? Where it considers a lone string as 1 item and the array as its respective item count?\
I can verify that the [JSON array](https://www.mindstick.com/forum/12870/how-to-parse-json-array-using-newtonsoft) is passed in properly.\
Any help is greatly appreciated!Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!\

## Replies

### Reply by AVADHESH PATEL

Hi Ankita!\
Array.isArray(x)\
will check for an array, although you'll need a polyfill (pretty easy to find) if you need to support legacy browsers.\
typeof x === "string"will indicate a string


---

Original Source: https://www.mindstick.com/forum/861/determine-if-single-value-or-sub-array-json

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
