Giter Club home page Giter Club logo

just.net's People

Contributors

benbenwilde avatar courela avatar eduardomb-aw avatar eduardomb08 avatar jorgecarneirotruphone avatar neptune3d avatar omarrodriguez15 avatar ramirezalejo avatar sdesyllas avatar workmaze avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

just.net's Issues

#ifcondition possible isue

To whom it may concern,
given the following JSON:
{ "total": 3, "data": [ { "PlacementId": 1, "candidate": { "CandidateId": 2311, "secondaryOwners": null, "owner": null, "id": 2311, "CustomUserId": 0 }, "approvingClientContact": null, "owner": { "id": 1949, "OwnerId": 1949 }, "CustomUserId": 42 }, { "PlacementId": 1, "candidate": { "CandidateId": 2311, "secondaryOwners": null, "owner": null, "id": 2311, "CustomUserId": 0 }, "approvingClientContact": null, "owner": { "id": null, "OwnerId": null }, "CustomUserId": 42 }, { "PlacementId": 1, "candidate": { "CandidateId": 2311, "secondaryOwners": null, "owner": null, "id": 2311, "CustomUserId": 0 }, "approvingClientContact": null, "owner": null, "CustomUserId": 42 } ] }
and the following transformation:
"Placement": { "data": { "#loop($.data)": { "CustomUserId": "#valueof($.CustomUserId)", "candidate": { "CandidateId": "#valueof($.candidate.CandidateId)" }, "clientCorporation": { "ClientCorporationId": "#valueof($.clientCorporation.ClientCorporationId)" }, "owner": { "OwnerId": "#ifcondition(#valueof($.owner),null,#valueof($.CustomUserId),#ifcondition(#valueof($.owner.OwnerId),null,#valueof($.CustomUserId),#valueof($.owner.OwnerId)))" } } } }

I get a null reference exception in the transformer. I cannot figure out the possible cause as the #ifcondition nesting seems to be fine. I have tried using #valueof(null) as the evaluation expression instead of just null but that did not seem to help. It generally evaluates to false of the owner is null.

If I use null the #ifcondition evaluates to false, but if I use #valueof(null) - I get an error, with the following transfomer:
#valueof($.owner),null,#valueof($.CustomUserId),#valueof($.owner.OwnerId)

Additional question - is there a way of accessing a variable from a "higher level" in the loop section? e.g. if "CustomUserId" was at the same level as "data".

#concat

Hi!

And this again I)

Is it possible to implement a concat method as #concat(#valueof(...),#const(...)) or #concat(#const(...),#valueof(...))?
In the current version impossible to make a concatenation with ','.
And would like to have a method #concat(#const([separator]),#valueof(...),#valueof(...),...), because join several fields looks as
"Document": "#concat(#concat(#concat(#concat(#concat(#concat(#valueof($.Citizenship), ; ),#valueof($.DocType)), ; ),#valueof($.DocNumber)), ; ),#valueof($.DocumentAdditionalInfo))"
And it is not the biggest line)

xconcat method does not work

Since version 4.02 the xconcat method does not work
System.Exception: Error while calling function : #xconcat(#valueof($.Model))

Currentvalueatpath in parent/parent of the parent... context

Currentvalueatpath evaluates the expression in the context of the current loop. Valueat evaluates expression in the global context.
Can we try to make a function that allows to get the value of the another context?
For example like this:
#currentvalueatpath(path is here, -1) would run in the parent loop.
Or some way of defining a scope by name, e.g.:
#loop(path, "parentScope")
...and then inner loop #loopwithincontext(path somewhere inside)
...and then getting the value #currentvalueatpath(path, "parentScope") //that would evaluate the path in the scope of "parentScope" named context

Source Code

Where is the source code for this component? Extremely interested in seeing this. Where can you get it?

JsonPath in Array question

I have this:
{
"Array": [
{
"Dog": "Fido",
"Treat": "Chewbone"
}
]
}

And this fails:
{ "Dog Pound": { "#loop($.Array)": "#currentvalueatpath($.Dog)" } }

I want this:

{ "Dog Pound": [ "Fido" ] }

Is there something wrong with my JsonPath? When I test it against a JsonPath tool, the path $.Array[*].Dog gets the value. So current value should be just $.Dog shouldn't it?

control characters

Thank you for solving the problem of the installation of the package.
But now another problem - it is control characters.

the input:

{
	"ArrivePlace": "Bryansk, \"Parkovaya\""
}

the exception:

Newtonsoft.Json.JsonReaderException: Additional text encountered after finished reading JSON content: ,. Path '', line 1, position 0.
   в Newtonsoft.Json.JsonTextReader.Read()
   в Newtonsoft.Json.Linq.JToken.Parse(String json, JsonLoadSettings settings)
   в Newtonsoft.Json.Linq.JToken.Parse(String json)
   в JUST.JsonTransformer.RecursiveEvaluate(JToken parentToken, String inputJson, JArray parentArray, JToken currentArrayToken)
   в JUST.JsonTransformer.Transform(String transformerJson, String inputJson)

A value type

Hi,
how can I retain a value type during a transformation?

the input:

{
	"id": 20,
	"active": true,
}

the transform:

{
	"typeId": "#valueof($.id)",
	"active": "#valueof($.active)"	
}

the output:

{
	"id": "20",
	"active": "True"
}

Support for nested loops

Is there a way to create a nested loop?
#loop(#currentvalueofpath(...)) ends with "Unexpected character while parsing path indexer: $”" error.

How to check the existence of a field in an array?

the input

{
	"Route": [
		{
			"index": 1,
			"arriveTime": "1970-01-01T19:29:00+03:00",
			"departTime": "1970-01-01T19:32:00+03:00",
			"name": "abc"
		},
		{
			"index": 2,
			"arriveTime": "1970-01-01T22:05:00+03:00",
			"departTime": "1970-01-01T22:15:00+03:00",
			"name": "def",
			"info": "info"
		}
	]
}

the transform

{
	"Route": {
			"#loop($.Route)": {			
				"Info": "#ifcondition(#exists(#currentvalueatpath($.info)),true,#currentvalueatpath($.info), )"
			}
		}
}

the output

System.Exception: Error while calling function : #ifcondition(#exists(#currentvalueatpath($.info)),true,#currentvalueatpath($.info), ) - Error while calling function : #exists(#currentvalueatpath($.info)) - Error while calling function : #currentvalueatpath($.info)

#replace() does not work for some situations

Given the following input:

{
  "theAnswer": 42,
  "bool": true,
  "pi": 3.141592653,
  "secret": "xyzzy",
  "complex": {
    "name1": {
      "first": "Mickey",
      "last": "Mouse"
    },
    "name2": {
      "first": "Donald",
      "last": "Duck"
    }
  } 
}

The following transformation works as expected:

{  "#": [ "#copy($)", "#replace($.complex.name1,#valueof($.complex.name2))" ] }

Holwever, the following transforms do not work as expected (in the first 7 examples, no replacement is performed; in the last example the value of "name1" is replaced with {}):

{ "#": [ "#copy($)", "#replace($.theAnswer,#valueof($.complex.name1.first))" ] }
{ "#": [ "#copy($)", "#replace($.theAnswer,#valueof($.complex.name1))" ] }
{ "#": [ "#copy($)", "#replace($.theAnswer,#valueof($.complex))" ] }
{ "#": [ "#copy($)", "#replace($.theAnswer,#valueof($.secret))" ] }
{ "#": [ "#copy($)", "#replace($.theAnswer,#valueof($.pi))" ] }
{ "#": [ "#copy($)", "#replace($.complex.name1.first,#valueof($.complex.name2.first))" ] }
{ "#": [ "#copy($)", "#replace($.complex.name1.first,#valueof($.complex.name2))" ] }
{ "#": [ "#copy($)", "#replace($.complex.name1,#valueof($.complex.name2.first))" ] }

Allow registration of custom functions for usability

Hi,
It would be very nice if it was possible to somehow "register" a dll with custom functions so they could be used like any built in function .. preferably like #myns::myfunc() syntax where myns is a custom namespace specified when registering dll/class.

I hope this makes sense ?

Thanks for a nice piece of software.

Nicolai

long type

Hi,
there is a problem with large numbers.

the input:

{
    "LogId":5000510625
}

the transform:

{
    "LogId": "#valueof($.LogId)"
}

and exception:

System.Exception: Error while calling function : #valueof($.LogId)
   в JUST.JsonTransformer.parseFunction(String functionString, String inputJson, JArray array, JToken currentArrayElement)
   в JUST.JsonTransformer.RecursiveEvaluate(JToken parentToken, String inputJson, JArray parentArray, JToken currentArrayToken)
   в JUST.JsonTransformer.Transform(String transformerJson, String inputJson)

custom function syntax

custom function syntax is really ugly. I am building an editor kinda thing and have a couple of custom functions.
instead of this long syntax
#customfunction(JUST.NET.Test,JUST.NET.Test.Season.findseason,#valueof($.tree.branch.leaf),#valueof($.tree.branch.flower))

i would like to have something like
$findseason(...)

in order for JUST to find my custom function, there could be a container and we could register our custom functions as such:

JUST.NET.CustomFunctions.Add(myCustomFunctionDll, methodName)

MIT license? Dependencies on GPL based libraries

Hi,

Since you're including Newtonsoft Json.Schema library, that's only available under GPL or commercial license, I don't think that you can use the MIT license. Or do I miss something here?

Juergen

Error: Object reference not set to an instance of an object.

I have a simple JUST map:
{
"work_notes": "#valueof($.work_notes)"
}

Works most of the time but when it is applied to the attached payload it throws "Object reference not set to an instance of an object." The property value is escaped JSON that I'm able to unescape.
test3.zip

What is causing the error? Is there something wrong with my data?

Operators in if-condition method

Hi,

I was try to use if-condition method with some operators like (<,>,>=,<=).

Is it possible to use with if-condition?

"{ 'has_items' : '#ifcondition(#valueof($.items[0].answers[?(@.number == 3 && @.type == 'number')].number),3,yes,no)' }"

Above, what I have tried. Thanks!

using #currentvalueatpath in jsonpath on looping not working

Hi,

I am trying to filter the array using jsonpath with #currentvalueatpath as below but not working..

Source Data : {
"PhoneTypeToSearch": "iPhone",
"Address": [
{
"City": "NewYork",
"name": "Jim"
},
{
"City": "NewYork",
"name": "John"
}
],
"people": [
{
"name": "Jim",
"phoneNumbers": [
{
"type": "iPhone",
"number": "0123-4567-8888",
"countryPrefix": "34"
},
{
"type": "work",
"number": "012567-8910"
}
]
},
{
"name": "John",
"phoneNumbers": [
{
"type": "iPhone",
"number": "0123-4562347-8888",
"countryPrefix": "43"
},
{
"type": "home",
"number": "0134523-4567-8910"
}
]
},
{
"name": "John"
}
]
}
Transformer -
{
"Persons": {
"#loop($.people)": {
"Address": "#valueof($.Address[?(@.name== '#currentvalueatpath($.name)')])"
}
}
}

however if I hardcode the filter value like "Address": "#valueof($.Address[?(@.name== 'Jim')])" then its working. but in my case I need pass the name under loop. any idea ?.

SumAtPath on fractions

Hi, it seems that the'sumathpath' function only operates on numbers and not on fractions. Are there any plans to support fractions in the future?

Problem with an array selector when looping

For a given JSON:

{
 "SomeObject": [
  {
   "State": "A"
  },
  {
   "State": "B"
  }
 ]
}

the JSONPath $.SomeObject[*] returns:

[
  {
    "State": "A"
  },
  {
    "State": "B"
  }
]

which is an array.

The transformer yields an error „Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'Newtonsoft.Json.Linq.JArray'.”
Any idea why it happens? I have double checked the path in the evaluator, and it seems to work fine.
When I removed the [*] it seems to work fine. Also, when the value is not found, the NullPointerException occurs. What to do when the field on which I am looping is not mandatory?

Issue with using #valueof inside quotes in DataTransform

Hello.

I've been trying to use #valueof inside double quotes within an xml attribute. However the DataTransformer.Transform doesn't transform this object. It just returns it as it is.

example :

Can you please let me know how can I transform attribute values?

Not to able to skip iteration in loop.

I want to transform Json that contains array. In one scenario, i want to skip iteration in loop. Is it possible to skip iteration on condition. As of now i want to skip first and last iteration

Empty array issue

transform
{
"array": "#valueof($.paths)"
}

source
{
"paths": [
{
"test": []
}
]
}

Exception with "[]"
System.NullReferenceException: 'Object reference not set to an instance of an object.'

Converting string value to number

Hi,
Actually I have two issues.
In every day work I have to convert XML to JSON and vice versa. Data types are loosed while converting from XML to JSON. For example:
15 is converted to { "age": "15" }, but should be { "age": 15 }.
So, I am wondering is it possible to add type conversion functions like #tolong(#valueof()), #todouble() and to #toboolean()?
Another issue relates to previous one. If I have large JSON structure, and I want to convert types only for few elements. What JSON template should I use? I don't want to write each field into template, but to do same way as in XSLT with template match; copy everything as is, but catch only some element and make operations on them.

Thank you in advance,
Lev

Incorrect transformation #currentvalueatpath

Good afternoon,

When using the method #currentvalueatpath , I noticed an incorrect transformation when the parameter is the datetimeoffset.

the input

{

    "Route": [
		{
	    	        "index": 1,
			"arriveTime": "1970-01-01T19:29:00+03:00",
			"departTime": "1970-01-01T19:32:00+03:00",
                        "name": "abc"
		},
		{
			"index": 2,
			"arriveTime": "1970-01-01T22:05:00+03:00",
			"departTime": "1970-01-01T22:15:00+03:00",
                        "name": "abc"
		}
	]
}

the transform

{
	"Route": {
		"#loop($.Route)": {
			"Index": "#currentvalueatpath($.index)",
			"ArriveTime": "#currentvalueatpath($.arriveTime)",
			"DepartTime": "#currentvalueatpath($.departTime)",
			"Point": "#currentvalueatpath($.name)"
		}
	}
}

the output

{
	"Route": [
		{
			"Index": "1",
			"ArriveTime": "01/01/1970 19:29:00",
			"DepartTime": "01/01/1970 19:32:00",
			"Point": "abc"
		},
		{
			"Index": "2",
			"ArriveTime": "01/01/1970 22:05:00",
			"DepartTime": "01/01/1970 22:15:00",
			"Point": "abc"
		}
	]
}

Support for Array as JSON

Hello, everyone. I'm writing this to ask if there's a way to pass, as a Transformer, an Array as JSON.

As example, this is what I have:

{
     "first": [
			{
				"sign-name": "Heart rate",
				"date": "2018-12-01",
				"value": 72
			},
			{
				"sign-name": "Heart rate",
				"date": "2018-12-03",
				"value": 65
			},
			{
				"sign-name": "Heart rate",
				"date": "2018-12-04",
				"value": 75
			},
		],
     "second": [
			{
				"sign-name": "Heart rate",
				"date": "2018-12-01",
				"value": 70
			},
			{
				"sign-name": "Heart rate",
				"date": "2018-12-03",
				"value": 55
			},
			{
				"sign-name": "Heart rate",
				"date": "2018-12-04",
				"value": 68
			},
		]
}

And my transformer would be something like this:

[{
    "title": "#valueof($.first[0].sign-name)",
    "uom": "bpm/min",
    "xLabel": "#valueof($.first[0].sign-name)",
    "yLabel": "bpm/min",
    "data": {
        "#loop($.first)": {
            "x": "#currentvalueatpath($.date)",
            "y": "#currentvalueatpath($.value)"
        }
    }
}, {
    "title": "#valueof($.second[0].sign-name)",
    "uom": "bpm/min",
    "xLabel": "#valueof($.second[0].sign-name)",
    "yLabel": "bpm/min",
    "data": {
        "#loop($.second)": {
            "x": "#currentvalueatpath($.date)",
            "y": "#currentvalueatpath($.value)"
        }
    }
}]

Unfortunately, this won't work because of an error:

Error during JUST transformation
Newtonsoft.Json.JsonReaderException: Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.

Am I doing something wrong? Or is it simply something I can't do? I thank you all in advance for any help you can give me.

InvokeCustomMethod failing when #currentvalueatpath is null

I am using a custom function to map a json property value from name to internal Id.

When the value is null JUST.net doesn't seem to pass the null value to the custom function (which is what I was expecting, but throws an exception.

From my analysis, this function is what is causing the problem.

       private static object GetTypedValue(Type pType, object val)
        {
            object typedValue = val;
            var converter = TypeDescriptor.GetConverter(pType);

           if (converter.CanConvertFrom(>>>>**val.GetType()**<<<<))
            {
                typedValue = converter.ConvertFrom(val);
            }
.....

As the val in above statement is null and causing Object reference not set.

Escape reserved characters

Characters like sharp, comma and round brackets are considered special characters, provide a way to escape them so they can be treated as plain text.

Relates to #59

Concat

Hellow!

How can I concatenate a parameter with a constant value?
And how can I concatenate several parameters, more than two and with a separator?

{
	"Name": "Ivan",
	"Surname": "Ivanov",
	"Patronymic": "Ivanovich"
}

=>

{
	"FullName": "Ivanov Ivan Ivanovich"
}

Noticed strange behavior:
input

{
	"Name": "Ivan",
	"Surname": "Ivanov"
}

transform

{
	"FullName": "#concat(#valueof($.Name),#valueof($.Surname))"
}

output

{
	"FullName": "IvanIvanov"
}

but if transform

{
	"FullName": "#concat(#valueof($.Name), #valueof($.Surname))"
}

then output

{
	"FullName": "Ivan, #valueof($.Surname))"
}

Is it an error or should it be?

#ifcondition - evaluate only the correct expression

When using #ifcondition, both true and false expressions are evaluated prior to knowing the result of the test condition. This can lead to errors when values used on these expressions are only available on one of the expressions.
Programming languages only evaluate one of the expressions according to the result of the test condition, apply the same logic here.

dotnetcore support

Is it going to be supported in .NET Standard?, Also will it be possible to expose Stream APIs, since if we have large data which required transformation, what will be memory footprint. In our case data might be large as 4 MB.

Data loss

How in the transformation does not lose the time zone?
{ "SendDate": "2017-04-26T19:27:00+03:00" }
After the transformation
{ "SendDate": "26.04.2017 19:27:00 }

Having source root ($) as an array

I wanted to use JUST.net to transform an API response, which is an array of elements into another array. JUST.net seems to treat the root element as a JObject instead of JToken and hence the root of the JSON ($) should always be an object and not an array.

I am currently working around by wrapping my API response inside an object and using a property accessor. Not having to deal with this unwanted wrapping would be great.

#valueof behaves as #currentvalueatpath

Hello and thank you for your awesome work!

I have JSON like this:

{ "prop": "hello", "arr": [ { "title": "item1" }, { "title": "item2" } ] }

and would like to get this:

{ "list": [ { "title": "item1", "prop": "hello" }, { "title": "item2", "prop": "hello" } ] }

I was hoping to use a transformer like this:

{ 'list': { '#loop($.arr)': { 'title': '#currentvalueatpath($.title)', 'prop': '#valueof($.prop)' } } }

But it seems "$" already refers to the root of the current iteration, and not the actual root of the document. So #valueof($.title) returns same thing as #currentvalueatpath($.title). I thought the purpose of #currentvalueatpath was to refer to the current iteration?

Is this intended? If so, any clues on how to achieve what I'm trying to do?

Thanks again!

How to rename a property name in a node

Considering transforming this JSON
{
"answers":[{"value": [{"id":1}]}]
}
to
{
"results":[{"spec-Id":1}]
}

I can write some transformation file like
{
"results": "#valueof($.answers[0].value)"
}
But how can I rename "Id" to "spec-Id"? Probably I can have a custom function to do the conversion. But I will lose the capability to reuse existing function that has been defined in the custom function, and if the $.answers[0].value becomes complex, the custom function will become big and it's meaningless to use the transform template.

String Contains: Can the second parameter be a string array?

#ifcondition(#stringcontains(#valueof($.d[0]),n),true,yes,no): Example from Just.Net git
In this example, we are trying to hard code n, instead can we check value of $.d[0] contains in an array of string [a,b,c,n].
do we have a way where we can do something like this?
#ifcondition(#stringcontains(#valueof($.d[0]),[a,b,c,n]),true,yes,no)

Does the transformer parse the input on every function call

It looks like the input json is passed around inside the transformer as a string and is parsed in each function that needs a JObject. Is there a reason for this? It looks like you could just pass the parsed JObject to each function saving the memory and time to parse. The only place I see that could cause issues is when you loopwithincontext where you reset the root json object, but I would think you could just parse the fragment in that scenario.

Our JSON input can be quite large and I'm worried about memory/time implications of parsing it multiple times.

Incorrect transformation doubles

Hi, first thank for great library.

Second, i find one issue when transforms float/doubles.
Actually function GetValue transform json to object float and sometimes has wrong.

How reproduce:
Example
{
"records":[
{
"id":"a83D000sdfhIAA",
"name":"700024",
"value_1":416889.0,
"value_2":1557597.06,
"value_3":1557597.06,
"value_4":1557597.06,
"value_5":17250.11,
"value_6":30.0
}
]
}

Transformer
{
"result":{
"#loop($.records)":{
"trans_id":"#currentvalueatpath($.id)",
"trans_name":"#currentvalueatpath($.name)",
"trans_value_1":"#currentvalueatpath($.value_1)",
"trans_value_2":"#currentvalueatpath($.value_2)",
"trans_value_3":"#currentvalueatpath($.value_3)",
"trans_value_4":"#currentvalueatpath($.value_4)",
"trans_value_5":"#currentvalueatpath($.value_5)",
"trans_value_6":"#currentvalueatpath($.value_6)"
}
}
}

Result

{
"result":[
{
"trans_id":"a83D000sdfhIAA",
"trans_name":"700024",
"trans_value_1":416889.0,
"trans_value_2":1557597.0,
"trans_value_3":1557597.0,
"trans_value_4":1557597.0,
"trans_value_5":17250.11,
"trans_value_6":30.0
}
]
}

I test change de returned value to double when the type is JTokenType.Float and work.
Captures:
screen shot 2019-02-14 at 4 19 48 pm

Other persons comment the same issue in the page
https://www.codeproject.com/Articles/1187172/JUST-JSON-Under-Simple-Transformation?fid=1921479&df=90&mpp=25&prof=True&sort=Position&view=Normal&spc=Relaxed&fr=1#_comments.
screen shot 2019-02-14 at 4 24 08 pm.
With this change work too.

Thanks.

JUSTContext constructor should allow to define the custom functions

JUSTContext constructor should be able to define the custom functions.
It shouldn't be required to instantiate a JUSTContext, and then execute the function RegisterCustomFunction.

Example:

var justContext = new JUSTContext 
{ 
    EvaluationMode = EvaluationMode.Strict 
   // a property to set the custom functions should be added here
};

// the line below should be unnecessary
justContext.RegisterCustomFunction("assemblyName", "fullname", "methodName", "methodAlias");

if-condition with multiple condition possibility

Hi,
as per our scenario am looking for if-condition with multiple conditions like if (country == 'US' and (State ='TX' || State = 'AR') then return country else return 'US', is there any possibility I can achive on this , even I tried with jsonPath as below, but no luck.

"{ 'has_items' : '#ifcondition(#valueof($.items[0].answers[?(@.number == 3 && @.type == 'number')].number),3,yes,no)' }

can you help on this ?.

Is it possible to flatten/transform this json input to this result with JUST?

Json input:

[
  {
    "target": "target1",
    "datapoints": [
      [
        "datapoint1_target1_x",
        "datapoint1_target1_y",
      ],
      [
        "datapoint2_target1_x",
        "datapoint2_target1_y",
      ],
    ]
  },
  {
    "target": "target2",
    "datapoints": [
      [
        "datapoint1_target2_x",
        "datapoint1_target2_y",
      ],
      [
        "datapoint2_target2_x",
        "datapoint2_target2_y",
      ],
    ]
  }
]

And want to flatten/transform this to following structure:


[
  {
    "target": "target1",
    "x": "datapoint1_target1_x",
    "y": "datapoint1_target1_y",
  },
  {
    "target": "target1",
    "x": "datapoint2_target1_x",
    "y": "datapoint2_target1_y",
  },
  {
    "target": "target2",
    "x": "datapoint1_target2_x",
    "y": "datapoint1_target2_y",
  },
  {
    "target": "target2",
    "x": "datapoint2_target2_x",
    "y": "datapoint2_target2_y",
  },
 ]

Thanks a lot

Check properties

Hi!
How can I verify a property exist or not empty?

I tried
but it doesnt work
#ifcondition(#valueof($.BuyDate),,,#concat( buy date: ,#valueof($.BuyDate)))

Thanks in advance.

Simple functions like add, subtract fails in Azure function using JUST.NETCore

Thanks for the beautiful tool for JSON transformation.
Quick question: I tried the examples that you have provided in GitHub using Visual Studio 2017 - Console application. Really works well.
When I tried to use the same piece of code and same example in Azure function, it fails and I get the below error. I have used JUST.NETCore in azure function
It happens for all add, subtract, multiply and divide also.
Simple example I have used
Input.json
{
"d": [ "one", "two", "three" ],
"numbers": [ 1, 2, 3, 4, 5 ]
}
Tranformer:
{
"mathresult": {
"add": "#add(#valueof($.numbers[0]),3)",
"subtract": "#subtract(#valueof($.numbers[4]),#valueof($.numbers[0]))",
"multiply": "#multiply(2,#valueof($.numbers[2]))",
"divide": "#divide(9,3)",
"round": "#round(10.005,2)"
}
}
Error:
Executed 'TranformData' (Failed, Id=)
[6/5/2019 3:20:18 PM] System.Private.CoreLib: Exception while executing function: TranformData. JUST.NETCore: Error while calling function : #add(#valueof($.a),#valueof($.b)) - Exception has been thrown by the target of an invocation.

All I need is
Input : a=10, b=20
transformer:
"add": "#add(#valueof($.a),#valueof($.b))"
Even this is also failing in Azure function using JUST.NETCore
Please do the needful

Int to string

Hi,
how can I convert int to string?

the input:
{
"Id": 123
}

I would like to get out
{
"Id": "123"
}

It doesnt work
{
"Id": "\"#valueof($.Id)\""
}

Filtering arrays

I'm trying to create a transform that just filters objects from an array, and it works, except the value is a string containing json objects instead of json objects.

A simple example:

I have JSON that looks like this:

{
  "products": [
    {
      "name": "p1",
      "type": "t1"
    },
    {
      "name": "p2",
      "type": "t2"
    },
    {
      "name": "p3",
      "type": "t1"
    }
  ]
}

Applying a transform that selects only those objects from the array with type t1:

{
  "t1_products": {
    "#loop($.products[?(@type=='t1')])": "#currentvalue()"
  }
}

I get this result:
{"t1_products":["{\"name\":\"p1\",\"type\":\"t1\"}","{\"name\":\"p3\",\"type\":\"t1\"}"]}

I was expecting:

{"t1_products":[{"name":"p1","type":"t1"},{"name":"p3","type":"t1"}]}

I have found if I create a new object in the loop like:

{
  "t1_products": {
    "#loop($.products[?(@type=='t1')])": {
      "product": "#currentvalue()"
    }
  }
}

Then I get json objects as the value of each product, but I'd rather not add an unnecessary object to the output.

How to create a dynamical field from the specific value of input.

Thanks for the great package.
For my special purpose, here is my expectation. Can I do that?

  • Input.json
    [
    {
    "ProductName": "xxxx",
    "Quantity": 1000
    }
    ]

Then,

  • Output
    [
    {
    "xxxx": 1000
    }
    ]

the "xxxx" can be anything from the input, for example. it could be "phone" or "laptop" or etc.

  • Output (phone)
    [
    {
    "phone": 1000
    }
    ]

Or,

  • Output (laptop)
    [
    {
    "phone": 1000
    }
    ]

Thanks for any suggestion.

Use the function inside of the JSONPath expression

Consider such a construction somewhere inside a loop:

someProp: #valueat($.someGlobalData[?(@.id==#currentvalueatpath($.id))])

That would allow me to achieve relational-like mapping!
From what I see it doesn't have to be very hard.
You can count the '[' and '(' and start evaluation of the # functions from the "deepest" place.
We can assume that those functions returns a simple value here...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.