Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file added .vs/Backend-Test/v17/.suo
Binary file not shown.
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
6 changes: 6 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ExpandedNodes": [
""
],
"PreviewInSolutionExplorer": false
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32516.85
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JsonConverterForm", "JsonConverterForm.csproj", "{F24451D8-F57B-4188-A0E1-83DB33A462C5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JsonConverterTests", "..\JsonConverterTests\JsonConverterTests.csproj", "{AACB34E8-8DA3-4F91-846D-0C120474CB6A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JsonConverter", "..\JsonConverter\JsonConverter.csproj", "{9D3B0754-5116-4672-885A-AAD5D5AC111B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F24451D8-F57B-4188-A0E1-83DB33A462C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F24451D8-F57B-4188-A0E1-83DB33A462C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F24451D8-F57B-4188-A0E1-83DB33A462C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F24451D8-F57B-4188-A0E1-83DB33A462C5}.Release|Any CPU.Build.0 = Release|Any CPU
{AACB34E8-8DA3-4F91-846D-0C120474CB6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AACB34E8-8DA3-4F91-846D-0C120474CB6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AACB34E8-8DA3-4F91-846D-0C120474CB6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AACB34E8-8DA3-4F91-846D-0C120474CB6A}.Release|Any CPU.Build.0 = Release|Any CPU
{9D3B0754-5116-4672-885A-AAD5D5AC111B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D3B0754-5116-4672-885A-AAD5D5AC111B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D3B0754-5116-4672-885A-AAD5D5AC111B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D3B0754-5116-4672-885A-AAD5D5AC111B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EFCBA264-807D-4882-AE19-E6463B314E22}
EndGlobalSection
EndGlobal
180 changes: 180 additions & 0 deletions Jacq_Botes_ONTRAPORT_Backend_Skills_Test/JsonConverterForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 90 additions & 0 deletions Jacq_Botes_ONTRAPORT_Backend_Skills_Test/JsonConverterForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using JsonConverter;
using Newtonsoft.Json.Linq;

namespace JsonConverterForm
{
public partial class JsonConverterForm : Form
{
public JsonConverterForm()
{
InitializeComponent();
}

private void rbToOneDimensionlContainer_CheckedChanged(object sender, EventArgs e)
{
if (rbToOneDimensionlContainer.Checked)
{
rbToMultiDimensionlContainer.Checked = false;
}
else
{
rbToMultiDimensionlContainer.Checked = true;
}
}

private void rbToMultiDimensionlContainer_CheckedChanged(object sender, EventArgs e)
{
tbOutput.Text = string.Empty;
tbInput.Text = string.Empty;

if (rbToMultiDimensionlContainer.Checked)
{
rbToOneDimensionlContainer.Checked = false;
}
else
{
rbToOneDimensionlContainer.Checked = true;
}
}

private void btnConvert_Click(object sender, EventArgs e)
{
Dictionary<string, JToken> multiDimentionalContainer = new Dictionary<string, JToken>();
Dictionary<string, object> oneDimentionalContainer = new Dictionary<string, object>();

if (tbInput.Text.Trim().Count() > 0)
{
if (rbToOneDimensionlContainer.Checked)
{
bool jsonValid = true;

try
{
multiDimentionalContainer = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, JToken>>(tbInput.Text);
}
catch (Exception ex)
{
MessageBox.Show($"Error deserializing JSON string with error: {ex.Message}", "Error Deserializing JSON", MessageBoxButtons.OK, MessageBoxIcon.Error);
jsonValid = false;
}

if (jsonValid)
{
oneDimentionalContainer = JsonConverter.JsonConverter.OneDimentionalDictionary_Create(multiDimentionalContainer);
tbOutput.Text = JsonHelper.SerializeWithCustomIndenting(oneDimentionalContainer);
}
}
else
{

bool jsonValid = true;
try
{
oneDimentionalContainer = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(tbInput.Text);
}
catch (Exception ex)
{
MessageBox.Show($"Error deserializing JSON string with error: {ex.Message}", "Error Deserializing JSON", MessageBoxButtons.OK, MessageBoxIcon.Error);
jsonValid = false;
}

if (jsonValid)
{
multiDimentionalContainer = JsonConverter.JsonConverter.MultiDimentionalJsonContainer_Create(oneDimentionalContainer);
tbOutput.Text = JsonHelper.SerializeWithCustomIndenting(multiDimentionalContainer);
}
}
}
}
}
}
19 changes: 19 additions & 0 deletions Jacq_Botes_ONTRAPORT_Backend_Skills_Test/JsonConverterForm.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\JsonConverter\JsonConverter.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Compile Update="JsonConverterForm.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>
</Project>
Loading