# How can i generate json with two-dimensional array?

**URL:** <https://forums.unrealengine.com/t/how-can-i-generate-json-with-two-dimensional-array/730324>\
**Category:** C++\
**Tags:** unreal-engine, json, question, CPP\
**Created:** [December 17, 2022, 6:16am UTC](https://forums.unrealengine.com/t/how-can-i-generate-json-with-two-dimensional-array/730324 "2022-12-17T06:16:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![HoyangUS](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HoyangUS](https://forums.unrealengine.com/u/HoyangUS)\
**Post date:** [December 17, 2022, 6:16am UTC](https://forums.unrealengine.com/t/how-can-i-generate-json-with-two-dimensional-array/730324/1 "2022-12-17T06:16:42Z")

</div>

I wanna generate json file with two-dimensional array as a property like below.

{  
“two\_dim\_array” : [[0.0, 0.1], [1.0, 1.1] ]  
}

How can i generate this json on UE ?

The example of one-dimensional array.

```auto
bool UGenerateTwoDimArrayiJson::GenerateTwoDimArrayJsonToFile(FString FilePath) {
	TSharedPtr<FJsonObject> JsonRootObject = MakeShareable(new FJsonObject);

	TArray<TSharedPtr<FJsonValue>> one_dim_array;
	one_dim_array.Add(MakeShareable(new FJsonValueNumber(0.0)));
	one_dim_array.Add(MakeShareable(new FJsonValueNumber(0.1)));
	one_dim_array.Add(MakeShareable(new FJsonValueNumber(1.0)));
	one_dim_array.Add(MakeShareable(new FJsonValueNumber(1.1)));

	JsonRootObject->SetArrayField("one_dim_array", one_dim_array);

	FString OutPutString;
	TSharedRef<TJsonWriter<>> Writer = TJsonWriterFactory<>::Create(&OutPutString);
	FJsonSerializer::Serialize(JsonRootObject.ToSharedRef(), Writer);
	
	return FFileHelper::SaveStringToFile(OutPutString, *FilePath);

```

---

<div class="post-metadata">

**Author:** ![koyama\_yu1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@koyama\_yu1](https://forums.unrealengine.com/u/koyama_yu1)\
**Post date:** [December 10, 2024, 1:39am UTC](https://forums.unrealengine.com/t/how-can-i-generate-json-with-two-dimensional-array/730324/2 "2024-12-10T01:39:24Z")

</div>

I solved like this

```auto
TArray<TSharedPtr<FJsonValue>> two_dimensional_Array;

TArray<TSharedPtr<FJsonValue>> first_dim_array;
	first_dim_array.Add(MakeShareable(new FJsonValueNumber(0.0)));
	first_dim_array.Add(MakeShareable(new FJsonValueNumber(0.1)));
	first_dim_array.Add(MakeShareable(new FJsonValueNumber(1.0)));
	first_dim_array.Add(MakeShareable(new FJsonValueNumber(1.1)));

TSharedRef<FJsonValueArray> first_dimData = MakeShareable(new FJsonValueArray(first_dim_array));

two_dimensional_Array.Add(firsr_dimData);

TArray<TSharedPtr<FJsonValue>> second_dim_array;
	second_dim_array.Add(MakeShareable(new FJsonValueNumber(0.0)));
	second_dim_array.Add(MakeShareable(new FJsonValueNumber(0.2)));
	second_dim_array.Add(MakeShareable(new FJsonValueNumber(2.0)));
	second_dim_array.Add(MakeShareable(new FJsonValueNumber(2.2)));

TSharedRef<FJsonValueArray>second_dimData = MakeShareable(new FJsonValueArray(second_dim_array));

two_dimensional_Array.Add(second_dimData);

```
