DataSet2JSON 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package DataSet2JSON --version 1.0.3
NuGet\Install-Package DataSet2JSON -Version 1.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DataSet2JSON" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DataSet2JSON --version 1.0.3
#r "nuget: DataSet2JSON, 1.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DataSet2JSON as a Cake Addin
#addin nuget:?package=DataSet2JSON&version=1.0.3

// Install DataSet2JSON as a Cake Tool
#tool nuget:?package=DataSet2JSON&version=1.0.3

This will convert the DataSet to JSON output as the name suggests.

Let's begin. Its just 1 steps process after adding the reference.

Create object for formatter

Code side changes

DataSet2JSON.Formatter convertToJSON = new DataSet2JSON.Formatter();
convertToJSON.FormatDataSet(ds);  // Your Dataset

This will return the output as JObject

Database side changes

First line of the select query should always be a config file.

select '1:Books';   // This is our configuration which will be explained
select id,booktitle from tbl_books;

Output

{
    "Books":[{
        "id":1,
        "booktitle":"Some text"
    },{
        "id":2,
        "booktitle":"Some text2"
    }]
}

By this you can understand that the config is converted to JSON. Now let us see how to change "id" of the Books to "BookID".

select '1:Books';
select id as BookID,booktitle as Title from tbl_books;

Output

{
    "Books":[{
        "BookID":1,
        "Title":"Some text"
    },{
        "BookID":2,
        "Title":"Some text2"
    }]
}

Now lets get only single book as output. The above Books is a list now I need a single object.

select '1:Books:single';

Output

{
    "Books":{
        "BookID":1,
        "Title":"Some text"
    }
}

If there is no book, then we might want to show a different message, and when book is found we might want to give the output of total books found with that matching title

IF EXISTS(SELECT id from tbl_books where booktitle like '%Hi%') THEN
	select '1:Status,2::singlevar';
	select '1' ResponseCode,'Success' ResponseDescription;
	select count(id) as TotalBooks from tbl_books where booktitle like '%Hi%'; -- Query B
ELSE
	select '1:Status';
	select '0' ResponseCode,'No Book Found' ResponseDescription;
END IF;

Output

--- If book is found with title
{
    "Status":{
        "ResponseCode":1,
        "ResponseDescription":"Success"
    },
	"TotalBooks":10 --- Here you can see the single value returned from Query B is a single object
}

--- If book is not found
{
    "Status":{
        "ResponseCode":0,
        "ResponseDescription":"No Book Found"
    }
}	

Let's consider you have a page with "Genre's" and you should the display the books under each Genre

Let us see how we can do this, to achieve the output i might need JSON in a Parent and child levels.

-- Scifi
----- Scifi book 1
----- Scifi book 2
-- Thriller
----- Thriller book 1
----- Thriller book 2

We should create a relation between the two tables here, tbl_genres and tbl_books. Lets assume that genreid is the column in tbl_books, id is the column in tbl_genres

select '1:Genres!1^id:2^genreid~1^Books';  --- we are using a seperator '!' here

--- If we convert the above to sql this is how it will be
--- tbl_genres.id = tbl_boards.genreid

select id,GenreName from tbl_genres;
select genreid,id as BookID,booktitle as Title from tbl_books;

Output

{
    "Genres":[{
				"GenreName":"Scifi",
				"Books":[{
					"BookID":3,
					"Title":"Scifi book 1"
				},{
					"BookID":4,
					"Title":"Scifi book 2"
				}]
			},
			{
				"GenreName":"Thriller",
				"Books":[{
					"BookID":5,
					"Title":"Thriller book 1"
				},{
					"BookID":6,
					"Title":"Thriller book 2"
				}]
			}]
}

There are some other feature which you can figure out what the output will be.

select '1:Genres,4:UserDetails!1^id:2^genreid~1^Books|2^authorid:3^id~2^Author:single'; 

Multiple relations are seperated by "|" in the config. To achieve this output. The relations are from right to left means "Leaf condition"|"Last leaf condition"

Use 😒ingle and see output and see without 😒ingle what is the difference.
Try 😒inglevar , this is not fully functionaly as of now.

A --- B

---B1 ---------C1

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net40 is compatible.  net403 was computed.  net45 was computed.  net451 is compatible.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2022.1.6 2,077 1/6/2022
2021.4.14 551 4/14/2021
1.0.4 1,237 7/2/2018
1.0.3 932 7/2/2018
1.0.2 930 7/1/2018
1.0.1 903 7/1/2018
1.0.0 928 7/1/2018

Testing with multiple versions of .net framework to package as one single project.