Codescovery.JsonServices 1.0.2

dotnet add package Codescovery.JsonServices --version 1.0.2                
NuGet\Install-Package Codescovery.JsonServices -Version 1.0.2                
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="Codescovery.JsonServices" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Codescovery.JsonServices --version 1.0.2                
#r "nuget: Codescovery.JsonServices, 1.0.2"                
#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 Codescovery.JsonServices as a Cake Addin
#addin nuget:?package=Codescovery.JsonServices&version=1.0.2

// Install Codescovery.JsonServices as a Cake Tool
#tool nuget:?package=Codescovery.JsonServices&version=1.0.2                

Codescovery JsonServices

Useful library to convert a json object to json paths. Also provides the ability to override the value from a json path.

Pre requisites

Your project must be running under .Net Core 3.1 or higher.

How to use

Dependency Injection

   public void ConfigureServices(IServiceCollection services)
        {
           ...
            services.AddJsonServices();
           ...
        }

Factory

var jsonService = JsonServiceFactory.Create();

Result

Take as example the following json:

  {
     "person":{
        "name":"FirstName",
        "age":30,
        "childs":[
           {
              "name":"child1",
              "age":16
           },
           {
              "name":"child2",
              "age":18
           }
        ],
        "likedFruits":[
           "apple",
           "banana"
        ]
     }
  }

The following code:

  var service = JsonServiceFactory.Create();
  var jsonPath = service.ConvertToJsonPath(json);
  var paths = jsonPath.GetJsonPaths();

Will return an IDictiorary<string,string> like this:

{
  "person":"{'name':'FirstName','age':30,'childs':[{'name':'child1','age':16},{'name':'child2','age':18}],'likedFruits':['apple','banana']}",
  "person.name":"FirstName",
  "person.age":"30",
  "person.childs":"[{'name':'child1','age':16},{'name':'child2','age':18}]",
  "person.childs[0].name":"child1",
  "person.childs[0].age":"16",
  "person.childs[1].name":"child2",
  "person.childs[1].age":"18",
  "person.likedfruits":"['apple','banana']",
  "person.likedfruits[0]":"apple",
  "person.likedfruits[1]":"banana"
}

Overriding Values

This library has the ability to override json values based on paths. Take this 2 jsons as examples.

JSON1

  {
     "person":{
        "name":"FirstName",
        "age":30,
        "childs":[
           {
              "name":"child1",
              "age":16
           },
           {
              "name":"child2",
              "age":18
           }
        ],
        "likedFruits":[
           "apple",
           "banana"
        ]
     }
  }

JSON2

{
   "person":{
      "name":"FirstName and LastName",
      "age":34,
      "likedFruits":[
         "pineapple",
         "avocado",
         "strawberry"
      ]
   }
}

If you use the following code:

  var service = JsonServiceFactory.Create();
  var result = service.OverrideJsonValuesFromPath(json2, json1, writeIdented: true);

It will return:

  {
     "person":{
        "name":"FirstName and LastName",
        "age":34,
        "childs":[
           {
              "name":"child1",
              "age":16
           },
           {
              "name":"child2",
              "age":18
           }
        ],
        "likedFruits":[
           "pineapple",
           "avocado",
           "strawberry"
        ]
     }
  }
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 netcoreapp3.1 is compatible. 
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
1.0.2 465 6/23/2021