I need to find this string:
{ "any string but :",
for example:
{ id,
{ this.content,
{ var = {123},
I'm searching it on Notepad++ with:
{ (.*?),
But I don't know how to exclude the : with
^\:\
Any help? thanks.
Undesire results:
{ id:id,
I'm searching for a javascript syntax error. By mistake, someone has defined JSONS as:
{ id, data, etc, etc,...}
When they have to be (this is the correct way):
{ id: id, data: something, etc:etc, etc:something,...}
So I want to find where that string doesn't have the : (which is correct)
You could use something like this:
{[^:]*?,
Working demo
Update: I noticed you updated your question. So, for your edited question you can use:
{[^:]*?,|(?<=, )\w+,
Working demo 2
Related
Below is the json blob that I have in my database
{
RootData: {
202003: {
201903: {
"abc": 123,
xyz: 456
},
data1: {
},
data2: {
}
}
}
}
Right now I have a query where to pull the data inside the node 201903 as below
select blah blah,
JSON_EXTRACT(convert(columnname using utf8), '$.RootData."202003"."201903".abc') as blah
In the above query, my question revolve around the part '$.RootData."202003"."201903".abc'
I DO NOT want to hard code the part 201903 and looking for a syntax where it can select the node with help of wildcard's.
I tried the below options with no luck
'$.RootData."202003"."20*".abc'
'$.RootData."202003".[1].abc'
'$.RootData."202003".$.20*.abc'
Not working as it is not correct syntax I guess. Looking for right syntax. 20 is always start of that key, we can depend on that.
And it is the first key always.
Path in the form $.RootData."202003"**.abc should help.
Refer - https://www.db-fiddle.com/f/6g4qiekAU4i3J8iRoAZiCA/0
The result type will be array. To fetch the first match result, the result can be nested in another JSON_EXTRACT as below
select JSON_EXTRACT(JSON_EXTRACT(convert(data using utf8), '$.RootData."202003"**.abc'), '$[0]')
from rootdata;
Can you please suggest how to get select fields from find method ?
e.g
let params = {
limit,
offset,
query: request
};
this.adapter.find(params)
Here, this will return all fields but instead of this I need only account_id from the resultset. I've already tried with fields inside params as well as settings{ fields: ["accout_id", "username"]} but doesn't work.
e.g
fields: ["account_id"]
Please guide me.
Thanks
Yes... I got the solution. I've used 'this.model' intead of 'this.adapter' like following way.
let params = {
limit,
offset,
query: request
};
this.model.find({
attributes: ['account_id'],
where : first_name : {
$like: '%Adam%'
}
})
Please forgive me if I use the incorrect terminology, I am quite the novice.
I have some simple JSON:
{
"properties": {
"footer.navigationLinks": {
"group": "layout"
, "default": [
{
"text": "Link a"
, "href": "#"
}
]
}
}
}
I am trying to pinpoint "footer.navigationLinks" but I am having trouble with the dot in the key name. I am using http://jsonpath.com/ and when I enter
$.properties['footer.navigationLinks']
I get 'No match'. If I change the key to "footernavigationLinks" it works but I cannot control the key names in the JSON file.
Please can someone help me target that key name?
Having a json response:
{
"0": {
"SKU": "somevalue",
"Merchant.Id": 234
}
}
I can target a key with a . (dot) in the name.
jsonPath.getJsonObject("0.\"Merchant.Id\"")
Note: the quotes and the fact that they are escaped.
Note not sure of other versions, but I'm using
'com.jayway.restassured', name: 'json-path', version: '2.9.0'
A few samples/solutions I've seen, was using singe quotes with brackets, but did not work for me.
For information, jsonpath.com has been patched since the question was asked, and it now works for the example given in the question. I tried these paths successfully:
$.properties['footer.navigationLinks']
$.properties.[footer.navigationLinks]
$.properties.['footer.navigationLinks']
$['properties']['footer.navigationLinks']
$.['properties'].['footer.navigationLinks']
properties.['footer.navigationLinks']
etc.
This issue was reported in 2007 as issue #4 - Member names containing dot fail and fixed.
The fix is not present in this online jsonpath.com implementation, but it is fixed in this old archive and probably in most of the forks that have been created since (like here and here).
Details about the bug
A comparison between the buggy and 2007-corrected version of the code, reveals that the correction was made in the private normalize function.
In the 2007-corrected version it reads:
normalize: function(expr) {
var subx = [];
return expr.replace(/[\['](\??\(.*?\))[\]']|\['(.*?)'\]/g, function($0,$1,$2){
return "[#"+(subx.push($1||$2)-1)+"]";
}) /* http://code.google.com/p/jsonpath/issues/detail?id=4 */
.replace(/'?\.'?|\['?/g, ";")
.replace(/;;;|;;/g, ";..;")
.replace(/;$|'?\]|'$/g, "")
.replace(/#([0-9]+)/g, function($0,$1){
return subx[$1];
});
},
The first and last replace in that sequence make sure the second replace does not interpret a point in a property name as a property separator.
I had a look at the more up-to-date forks that have been made since then, and the code has evolved enormously since.
Conclusion:
jsonpath.com is based on an outdated version of JSONPath and is not reliable for previewing what current libraries would provide you with.
You can encapsulate the 'key with dots' with single quotes as below
response.jsonpath().get("properties.'footer.navigationLinks'")
Or even escape the single quotes as shown:
response.jsonpath().get("properties.\'footer.navigationLinks\'")
Both work fine
This should be a fairly simple one.
myobject has various properties, _id, name, createdBy, date etc
In my find query I want to only return specific fields from within myObject. So for example, what would I need to do to modify the find query below so that only name was returned?
myCollection.find({createdBy: someId}, {fields: {myObject: 1}}).fetch();
Currently this will return everything in myObject which it should do, I just want one field within myObject returned.
Here is a way to do it within the query:
myCollection.find({createdBy: someId}, {fields: {'myObject.name':
1}}).fetch();
Note the quotes around
'myObject.name'
Lets assume we are talking about posts, and a post document looks like this:
{
_id: 'abc123',
title: 'All about meteor',
author: {
firstName: 'David',
lastName: 'Weldon'
}
}
You can then extract all of the last names from all of the authors with this:
var lastNames = Posts.find().map(function(post) {
return post.author.lastName;
});
Modify the selector and options as needed for your collection. Using fields in this case may be a small optimization if you are running this on the server and fetching the data directly from the DB.
I have a document like this:
{
Name : val
AnArray : [
{
Time : SomeTime
},
{
Time : AnotherTime
}
...arbitrary more elements
}
I need to update "Time" to a Date type (right now it is string)
I would like to do something psudo like:
foreach record in document.AnArray { record.Time = new Date(record.Time) }
I've read the documentation on $ and "dot" notation as well as a several similar questions here, I tried this code:
db.collection.update({_id:doc._id},{$set : {AnArray.$.Time : new Date(AnArray.$.Time)}});
And hoping that $ would iterate the indexes of the "AnArray" property as I don't know for each record the length of it. But am getting the error:
SyntaxError: missing : after property id (shell):1
How can I perform an update on each member of the arrays nested values with a dynamic value?
There's no direct way to do that, because MongoDB doesn't support an update-expression that references the document. Moreover, the $ operator only applies to the first match, so you'd have to perform this as long as there are still fields where AnArray.Time is of $type string.
You can, however, perform that update client side, in your favorite language or in the mongo console using JavaScript:
db.collection.find({}).forEach(function (doc) {
for(var i in doc.AnArray)
{
doc.AnArray[i].Time = new Date(doc.AnArray[i].Time);
}
db.outcollection.save(doc);
})
Note that this will store the migrated data in a different collection. You can also update the collection in-place by replacing outcollection with collection.