Frends Community Tasks to process Json data.
You can install the Task via Frends UI Task View or you can find the NuGet package from the following NuGet feed https://www.myget.org/F/frends-community/api/v3/index.json and in Gallery view in MyGet https://www.myget.org/feed/frends-community/package/nuget/Frends.Community.JSON
Clone a copy of the repo
git clone https://github.com/CommunityHiQ/Frends.Community.JSON.git
Build the project
dotnet build
Run Tests
dotnet test
Create a NuGet package
dotnet pack --configuration Release
When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.
- Fork the repo on GitHub
- Clone the project to your own machine
- Commit changes to your own branch
- Push your work back up to your fork
- Submit a Pull request so that we can review your changes
NOTE: Be sure to merge the latest from "upstream" before making a pull request!
Frends task for enforcing types in Json documents. The main use case is when you e.g. convert XML into Json and you lose all the type info in the resulting Json document. With this task you can restore the types inside the Json document.
Property | Type | Description | Example |
---|---|---|---|
Json | string |
Json document to process | { "prop1": "123", "prop2": "true" } |
Rules | Array[JsonTypeRule] |
Rules for enforcing | [ { "$.prop1", Number }, { "$.prop2", Boolean } ] |
Property | Type | Description | Example |
---|---|---|---|
Json path | string |
Json path for the rule to use | $.prop1 |
Data type | Enum<> | Data type to enforce | String |
The result is a Json string with types converted. Given the following input:
Json: { "prop1": "123", "prop2": "true" }
Rules:
"$.prop1" => Number
"$.prop2" => Boolean
The output would be: { "prop1": 123.0, "prop2": true }
The JsonMapper task is meant for simple Json to Json transformation using JUST.net library. It can also be used for Json to XML or CSV transformation, but it is not recommeded.
Input Json is validated before the actual transformation is executed. If the input is invalid or transformation fails, an exception is thrown.
Property | Type | Description | Example |
---|---|---|---|
Input json | string or JToken |
Source Json to transform. Has to be String or JToken type. | {"firstName": "Jane", "lastName": "Doe" } |
Json map | string |
JUST transformation code. See JUST.Net documentaion for details of usage | {"fullName": "#xconcat(#valueof($.firstName), ,#valueof($.lastName))"} |
The result is an object with following properties
Property | Type | Description | Example |
---|---|---|---|
Result | string |
Contains transformation result. | { "fullName" : "Jane Doe" } |
ToJson() | JToken |
Method that returns Result string as JToken type. |
Simple example of combining two values from source Json:
Input Json:
{
"firstName": "John",
"lastName": "Doe"
}
Json Map:
{
"Name": "#xconcat(#valueof($.firstName), ,#valueof($.lastName))"
}
Transformation result:
{
"Name": "John Doe"
}
Json which root node is of type array does not work. It has to wrapped around an object. Example:
Input
[{
"Name": "John Doe"
},
{
"Name": "John Doe"
}]
with Json Map
{
"Name": "#valueof($.[0].firstName)"
}
throws exception in transformation. This can be avoided by wrapping Input Json as follows:
{ "root":
[{
"Name": "John Doe"
},
{
"Name": "John Doe"
}]
}
Version | Changes |
---|---|
1.0.0 | Initial implementation. Two different tasks combined to one repo. |
1.0.1 | Updated version number to fix release CI |
1.0.2 | Fixed issue where null values are forced as array of null values. |
1.0.3 | Downgraded Newtonsoft.Json to make make task work in Frends 5.3. |
1.0.4 | JsonMapper: Updated JUST.Net to fix issue with concurrect execution of the Task. |