Is there any syntax for a json path query to return the root object?
To quote Goessner on the subject:
Since a JSON structure is usually anonymous and doesn't necessarily have a "root member object" JSONPath assumes the abstract name $ assigned to the outer level object.
So I'd really expect just "$" to return the root object... But it doesn't. It returns false.
I need a way to get the root object in a query (seems silly I know but the application I am using only allows me to specify a jsonpath query to access items in JSON).
$ does return the root object for Jayway, Gatling and Nebhale.
Looks like the equivalent in Goessner is $..
Related
I have a JSON like this
{
"a" : 1,
"key_to_find" : "value_of_key",
"nested" : {
"value_of_key" : "real_value",
"b" : 2
}
}
I want to create a JSON Path expression to get "real_value", but I don't now the key "value_of_key" so I need to dynamically reference it.
I tried something like:
$.nested['$.key_to_find']
but it doesn't work.
How can I reference to root element value as key to get children values? Is that possible?
I need to use it inside AWS Step Functions, so no programming languages/libraries can be used.
References like this aren't part of JSON Path, though I think since you're using them inside AWS, you'll need to see exactly what they support. It varies. Widely.
We (the team working on the coming specification) have looked at the idea of a key() or index() function, however. You may find this discussion enlightening as well.
I actually solved my problem before posting, but I wonder if there are any better solutions?
Also if there is somewhere where there is a way to use list as-is?
I am writing a simple get endpoint if F# which needs to accept a list of strings as an argument.
I take that list as the input to a query that runs as expected, I am not worried about that part.
The problem I am facing is as follows (minimal implmenetation):
When I define the endpoint as:
[<HttpGet>]
member _.Get() =
processStrings [ "test"; "test2" ]
it returns as expected.
When I change it to:
[<HttpGet>]
member _.Get([<FromQuery>] stringList: string list) = processStrings stringList
I get an error:
InvalidOperationException: Could not create an instance of type 'Microsoft.FSharp.Collections.FSharpList`1[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]'. Model bound complex types must not be abstract or value types and must have a parameterless constructor. Record types must have a single primary constructor. Alternatively, give the 'stringList' parameter a non-null default value.
Which doesn't make much sense to me, as I am using a list of strings, which in C# at least defaults to an empty list.
So I assume this comes down to how C# and F# interpret these signatures, but I am not sure how to resolve it.
I tried this signature and received the same error as above....
member _.Get( [<Optional; DefaultParameterValue([||]); FromQuery>] stringList: string list) = processStrings stringList
In the end using the following did solve the problem.
member _.Get( [<Optional; DefaultParameterValue([||]); FromQuery>] stringList: string seq) = processStrings stringList
I assume it was solved because seq is just IEnumerable, and then presumable list isn't just List from C# (mutable vs immutable). But is there a way to use an F# list in [FromQuery] parameters? Would [FromBody] have just worked? (No is the tested answer) Is there a way to add a type provider for an endpoint like this?
Is there something else I am missing here? Mine works now, but I am curious to the implications of the above.
I have not tested this, but I would assume that ASP.NET does not support F# lists as arguments. I would guess that taking the argument as an array would be much more likely to work:
[<HttpGet>]
member _.Get([<FromQuery>] stringList: string[]) =
processStrings (List.ofArray stringList)
I am using Application Insights Log-Explorer query window to visualize the below query.
Inside the field customDimensions.RemotePC I am string a json payload.
When I try to index the stored json via propery-indexing, i get the value as null. I tried to access it as array that turns null as well.
Could you please help me to access the FirstName property in below diagram.
Try this:
| extend todynamic(tostring(rpc)).FirstName
I believe that the issue is that rpc is string (although it looks as json). Thus you need to "cast" it to dynamic. You first need to tell the compiler though that this is a string value.
If I pass an Object into the model and test it with the "?is_string" built-in, it will falsely return a true value.
Is it possible (without checking the class name) to have a proper type checks on Objects?
FreeMarker: 2.3.28
Code to reproduce:
public class Test {}
// In Test Controller
ModelAndView mv = new ModelAndView("test");
mv.addObject("test", new Test());
// In test.ftl
<#if test?is_string>
${test} - is a string!
</#if>
// Result
Test#455b31c - is a string
The problem is that that approach isn't really supported by FreeMarker. The Java objects are mapped to some template language values via Configuration.objectWrapper, and the template only sees the result of that mapping. Furthermore the template language has a different type system than Java, a simplistic one, without classes. (It was a design goal back then that the data-model is just some simple tree, and the templates will work no mater what objects are behind, as far as it still gives the same tree.) ?is_... doesn't check the Java type, but the type according the template language. As with the usual ObjectWrapper-s a "generic" object (means, nothing recognized like List, Map, Date, etc.) can be used as a strings whose value is whatever toString() returns, it's a string as far as the template language is concerned. It's kind of duck typed...
A workaround I can think of is that first check the value with ?is_hash, as that will catch the said generic objects (as they support ., they are hashes as well, not just strings). Or instead just check the property you expect to be present in a Test. Then on the "else" branch you can continue with ?is_string.
I have an object which has a realm array within it.
To use an example they use in their docs:
#interface Person : RLMObject
// ... other property declarations
#property RLMArray<Dog *><Dog> *dogs;
#end
So I would like to know the proper way to say "Give me all person objects which own a dog named fido"? I can't seem to find a way without making a back linking or writing a for loop. Is there a clean solution to this type of query in Realm?
The query you're after would be expressed as:
[Person objectsWhere:#"ANY dogs.name == 'fido'"]
The ANY / ALL / NONE modifiers describe how many members of the array must match the subpredicate in order for the predicate to be treated as a match.