I am trying to get a single key from firebase nodes and I can't get any from the code I have right now. Here is my code:
let app = Firebase.initializeApp(config)
let db = app.database()
let bdRef = db.ref()
export default {
name: 'hello',
firebase: {
businesses: bdRef.orderByChild('.key').equalTo('306')
}
}
I get this error when doing this:
validation.js?5c80:234 Uncaught Error: Query.orderByChild failed: First argument was an invalid path = ".key". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"`
When I do this with my code:
businesses: bdRef.orderByChild('title').equalTo('Feather Animation Wood Carving Supplies')
It comes with this array:
0:Object
.key:"3021"
address:"Hello Avenue"
city:""
description:"Wood carving tools and supplies. Please contact us by phone or internet."
email:"hi#gmail.com"
employees:"1"
How do I get the .key property?
Did you try use this command:
businesses['.key']
Its very simple answer that you have json with ".key" key and "3021" as its value. But in ".key" you have included "." which refers that you are giving empty path or maybe invalid path.
So if you name it as "key" or any name as "keyid" would be cool, unless you include as your error says can't contain ".", "#", "$", "[", or "]"
Hope this explanation helped!
As stated, you cannot query a property with a dot in its name. From the documentation, you need to use the built in orderByKey() filter instead:
export default {
name: 'hello',
firebase: {
businesses: bdRef.equalTo('306').orderByKey()
}
}
Related
I am attempting to use the extractjson() method that includes email addresses in the source data (specifically the # symbol).
let T = datatable(MyString:string)
[
'{"user#domain.com": {"value":10}, "userdomain.com": { "value": 5}}'
];
T
| project extractjson('$.["user#domain.com"].value', MyString)
This results in a null being returned, changing the JSONPath to '$.["userdomain.com"].value' does return the correct result.
Results
I know the # sign is a used as the current node in a filter expression, does this need to be escaped when used with KQL?
Just as a side note, I run the same test using nodes 'jsonpath' package and this worked as expected.
const jp = require('jsonpath');
const data = {"user#domain.com": {"value":10}, "name2": { "value": 5}};
console.log(jp.query(data, '$["user#domain.com"].score'));
you can use the parse_json() function instead, and when you don't have to use extract_json():
print MyString = '{"user#domain.com": {"value":10}, "userdomain.com": { "value": 5}}'
| project parse_json(MyString)["user#domain.com"].value
MyString_user#domain.com_value
10
From the documentation: https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/extractjsonfunction
I am creating a composer from terraform where I want to pass a json as input variable
Terraform code:
software_config{
env_variables{
AIRFLOW_VAR_MYJSON ="{'__comment1__': 'This the global section', 'project_id':'testproject', 'gce_zone':'us-east1-c', 'gce_region':'us-east1','networkname':'vpc1', 'subnetwork':'https://www.googleapis.com/compute/v1/projects/testproject/regions/us-east1/subnetworks/subnet1'}"
}
}
I am trying to read the value of AIRFLOW_VAR_MYJSON in DAG , but it is not working as the value is not recognized as JSON.
I tried converting it and then deserializing it with following code:
JSONList = Variable.get("MYJSON")
jsonvar = json.dumps(JSONList)
setting_var = Variable.set("settings", jsonvar)
dag_config = Variable.get("settings", deserialize_json=True)
but it is not working.
I have also tried using
dag_config =json.loads(jsonvar)
then reading value as
project_id = dag_config["project_id"]
but I get error : "string indices must be integers"
Please suggest a way to resolve this.
NOTE : I know the gcloud command to set variables from json file but that is not working in my case as the project is in VPC and kubernetes clusters are giving timeout or handshake error, so I have ruled out use of this option
Valid JSON can only be " not '. Try switching the quotes.
A value can be a string in double quotes, or a number, or true or false or null, or an object or an array.
software_config{
env_variables{
AIRFLOW_VAR_MYJSON ="{\"__comment1__\": \"This the global section\", \"project_id\":\"testproject\", \"gce_zone\":\"us-east1-c\", \"gce_region\":\"us-east1\",\"networkname\":\"vpc1\", \"subnetwork\":\"https://www.googleapis.com/compute/v1/projects/testproject/regions/us-east1/subnetworks/subnet1\"}"
}
}
Or a little nicer way:
software_config {
env_variables {
AIRFLOW_VAR_MYJSON = jsonencode({
"__comment1__" = "This the global section",
"project_id" = "testproject",
"gce_zone" = "us-east1-c",
"gce_region" = "us-east1",
"networkname" = "vpc1",
"subnetwork" = "https://www.googleapis.com/compute/v1/projects/testproject/regions/us-east1/subnetworks/subnet1",
})
}
}
I'm trying to get some info from some JSON I got from magicthegathering.io using the SelectTokens method in JSON.Net. However, when I try to do this I get an error "Could not read query operator".
Here's the code I'm using:
JToken jtoken = JToken.Parse(
#"{""cards"":[{""name"":""Krark-Clan Engineers"",""manaCost"":""{3}{R}"",""cmc"":4,""colors"":[""Red""],""type"":""Creature — Goblin Artificer"",""types"":[""Creature""],""subtypes"":[""Goblin"",""Artificer""],""rarity"":""Uncommon"",""set"":""5DN"",""text"":""{R}, Sacrifice two artifacts: Destroy target artifact."",""flavor"":""\""Well, I jammed the whatsit into the whackdoodle, but I think I broke the thingamajigger.\"""",""artist"":""Pete Venters"",""number"":""70"",""power"":""2"",""toughness"":""2"",""layout"":""normal"",""multiverseid"":50201,""imageUrl"":""http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=50201&type=card"",""foreignNames"":[{""name"":""喀勒克族机械工"",""language"":""Chinese Simplified"",""multiverseid"":81620},{""name"":""Ingénieurs du clan Krark"",""language"":""French"",""multiverseid"":80795},{""name"":""Ingenieure des Krark-Clans"",""language"":""German"",""multiverseid"":80960},{""name"":""Ingegneri di Krark-Clan"",""language"":""Italian"",""multiverseid"":81290},{""name"":""クラーク族の技師"",""language"":""Japanese"",""multiverseid"":80630},{""name"":""Engenheiros do Clã-de-Krark"",""language"":""Portuguese (Brazil)"",""multiverseid"":81455},{""name"":""Ingenieros del clan Krark"",""language"":""Spanish"",""multiverseid"":81125}],""printings"":[""5DN""],""originalText"":""{R}, Sacrifice two artifacts: Destroy target artifact."",""originalType"":""Creature — Goblin Artificer"",""legalities"":[{""format"":""Commander"",""legality"":""Legal""},{""format"":""Freeform"",""legality"":""Legal""},{""format"":""Legacy"",""legality"":""Legal""},{""format"":""Mirrodin Block"",""legality"":""Legal""},{""format"":""Modern"",""legality"":""Legal""},{""format"":""Prismatic"",""legality"":""Legal""},{""format"":""Singleton 100"",""legality"":""Legal""},{""format"":""Tribal Wars Legacy"",""legality"":""Legal""},{""format"":""Vintage"",""legality"":""Legal""}],""id"":""a4d05fd27ec5d7df470e91218f1ca885eda4f0c6""}]}"
);
var foundTokens = jtoken.SelectTokens(#"$..cards[?(#.name=""Krark - Clan Engineers"")].imageUrl", true);
if (foundTokens.Any())
{
string selected = foundTokens.Last().ToString();
Console.WriteLine("Found: " + selected);
}
else
{
Console.WriteLine("Found nothing!");
}
(Here is a fiddle with the same code as shown above.)
When I try to get the same path using online JSONPath testing tools (here or here for example) it works as expected.
Why doesn't this work in JSON.Net? And how can I fix it?
Thanks!
You have to use == for string comparison; = is only for numerical values.
You have to enclose your string in single quotes.
e.g. #.name=='Krark - Clan Engineers')
forked fiddle
I have been navigating map structures fine for a long time now. Yet, for some reason, the root of this problem escapes me. I've tried bracket notation as well, no luck.
Why doesn't the final output (null) return "[serverinfo:[listenPort:19001]]"
If I replace the two instances of ' "$instanceName" ' with simply ' services ', it works.
String instanceName = "Services"
Map serverNode = [
instances:[
"$instanceName":[
serverinfo:[
listenPort:19001
]
]
]
]
println "$instanceName"
println serverNode.instances
println serverNode.instances."$instanceName"
//output
Services
[Services:[serverinfo:[listenPort:19001]]]
null
The type of "$instanceName" is GStringImpl, not String. It's a common mistake (and hard to find!)
def serverNode = [
instances:[
("$instanceName" as String):[
serverinfo:[
listenPort:19001
]
]
]
]
as stated by #tim_yates in comment, if your interpolated string is as simple as in this example (ie ,"${property}"), then you can use the (property) syntax : Groovy put the value of the property as a key, not the word "property"
//controller code.
var fireurl = 'https://someuerid.firebaseio.com/'
var usersref = new Firebase(fireurl);
angularFire(usersref.limit(10), $scope, "userConcalls");
//view code
<li ng-repeat="(key, value) in userConcalls">key:{{key}} value: {{value}} </li>
Error
Uncaught Error: Firebase.child failed: First argument was an invalid path: ".priority". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"
Your code is correct. But it looks like you were violating the character set limitations for Firebase references. How exactly does you data structure look like? See https://www.firebase.com/docs/creating-references.html