> For the complete documentation index, see [llms.txt](https://docs.starcounter.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.starcounter.io/2.3.2/guides/typed-json/primitive-arrays-and-single-value-types.md).

# Primitive Arrays and Single Value Types

## Introduction

You can create JSON-by-example that contains a primitive value, object, or array. In C#, all of these are handled the same way.

## Type Checking

&#x20;To check the type of a `Json`-instance, use one of these properties:

* `IsBoolean`
* `IsDecimal`
* `IsDouble`
* `IsInteger`
* `IsString`
* `IsObject`
* `IsArray`

```javascript
123
```

```csharp
var json = new SimpleIntegerJson();
Debug.WriteLine(json.IsInteger); // => true
Debug.WriteLine(json.IsString); // => false
```

## Getting and Setting Single Value Types

&#x20;To get or set values, use one of these properties:

* `BooleanValue`
* `DecimalValue`
* `DoubleValue`
* `IntegerValue`
* `StringValue`

```javascript
"simple string"
```

```csharp
var json = SimpleStringJson();
Console.WriteLine(json.StringValue); // => simple string
json.StringValue = "another string";
Console.WriteLine(json.StringValue); // => another string
```

&#x20;Trying to get or set to values of a different type will throw `InvalidOperationException`:

```javascript
"simple string"
```

```csharp
var json = SimpleStringJson();
Console.WriteLine(json.IsInteger); // => false
json.IntegerValue = 123; // InvalidOperationException
```

## Getting and Setting Primitive Arrays

&#x20;Values are added to arrays with the `Add` method. To get the values of an array, use `ToJson`.

```javascript
[ ]
```

```csharp
var json = new SingleArrayJson();

json.Add().IntegerValue = 1;
json.Add().StringValue = "foo";

Console.WriteLine(json.ToJson()); // [1, "foo"]
```

In the example above, the array holds values of different types. To restrict the array to one type, add a value of the type you want in the JSON-by-example. This value will not be included in the resulting JSON.

```javascript
[ 99 ]
```

```csharp
var json = new SingleArrayJson();

Console.WriteLine(json.ToJson()); // => []
json.Add().IntegerValue = 4;
json.Add().IntegerValue = 2;
Console.WriteLine(json.ToJson()); // => [4, 2]
json.Add().StringValue = "foo"; // InvalidOperationException
```

&#x20;Adding strings can be further simplified with an overload of `Add`:

```csharp
var json = EmptyArrayJson();
json.Add("foo");
Console.WriteLine(json.ToJson()); // => ["foo"]
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.starcounter.io/2.3.2/guides/typed-json/primitive-arrays-and-single-value-types.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
