Unable to figure out what format is this - format

I'm querying a database and one of the fields contains a string in the following format:
ids {
Id: 12
Id: 12345
Id: 67891
}
Sorry if this is a stupid question, but this obviously isn't JSON since it doesn't have quotes, no commas to separate the values, and the keys are all the same.
Does anyone have any idea what the above format is called?
Thanks!

Related

Powerautomate Parsing JSON Array

I've seen the JSON array questions here and I'm still a little lost, so could use some extra help.
Here's the setup:
My Flow calls a sproc on my DB and that sproc returns this JSON:
{
"ResultSets": {
"Table1": [
{
"OrderID": 9518338,
"BasketID": 9518338,
"RefID": 65178176,
"SiteConfigID": 237
}
]
},
"OutputParameters": {}
}
Then I use a PARSE JSON action to get what looks like the same result, but now I'm told it's parsed and I can call variables.
Issue is when I try to call just, say, SiteConfigID, I get "The output you selected is inside a collection and needs to be looped over to be accessed. This action cannot be inside a foreach."
After some research, I know what's going on here. Table1 is an Array, and I need to tell PowerAutomate to just grab the first record of that array so it knows it's working with just a record instead of a full array. Fair enough. So I spin up a "Return Values to Virtual Power Agents" action just to see my output. I know I'm supposed to use a 'first' expression or a 'get [0] from array expression here, but I can't seem to make them work. Below are what I've tried and the errors I get:
Tried:
first(body('Parse-Sproc')?['Table1/SiteConfigID'])
Got: InvalidTemplate. Unable to process template language expressions in action 'Return_value(s)_to_Power_Virtual_Agents' inputs at line '0' and column '0': 'The template language function 'first' expects its parameter be an array or a string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#first for usage details.'.
Also Tried:
body('Parse-Sproc')?['Table1/SiteconfigID']
which just returns a null valued variable
Finally I tried
outputs('Parse-Sproc')?['Table1']?['value'][0]?['SiteConfigID']
Which STILL gives me a null-valued variable. It's the worst.
In that last expression, I also switched the variable type in the return to pva action to a string instead of a number, no dice.
Also, changed 'outputs' in that expression for 'body' .. also no dice
Here is a screenie of the setup:
To be clear: the end result i'm looking for is for the system to just return "SiteConfigID" as a string or an int so that I can pipe that into a virtual agent.
I believe this is what you need as an expression ...
body('Parse-Sproc')?['ResultSets']['Table1'][0]?['SiteConfigID']
You can see I'm just traversing down to the object and through the array to get the value.
Naturally, I don't have your exact flow but if I use your JSON and load it up into Parse JSON step to get the schema, I am able to get the result. I do get a different schema to you though so will be interesting to see if it directly translates.

Rails 6 Remove specific error - delete(:email)

I know I can use user.errors.delete(: email) to delete the email validation error, but if an email has multiple errors on it, I assume it would remove all the errors associated with email.
Do rails have a way to delete a specific error message? I would like to remove the :already_confirmed error only. Looking for something like: user.errors.delete( email: :already_confirmed)
=> #<ActiveModel::Errors:0x007feee7ab60ere8
#base=
#<User id: 123, email: "some#domain.com", created_at: "2020-09-26 19:00:38", updated_at: "2020-09-26 19:01:27", first_name: nil, last_name: nil>,
#details={:email=>[{:error=>:already_confirmed}]},
#messages={:email=>["was already confirmed, please try signing in"]}>
There should really be a user.errors.remove() method in rails. However, this is how I did it, but I am still hoping for a cleaner way.
error_index = user.errors.details[:email].find_index{|i| i[:error] == :already_confirmed}
if error_index.present?
user.errors.messages[:email].delete_at(error_index)
user.errors.details[:email].delete_at(error_index)
end
ActiveModel doesn't support any interface to delete specific errors
But you can something like this:
errors.details[:email].reject! { |detail| detail >= { error: :taken } }
errors.messages[:email].delete(t("activerecord.errors.messages.taken"))
It's not very elegant. But I haven't found a more beautiful solution yet
First line contains Hash#>= method. It returns true if one hash is part of another. In the example above, the error hash (detail) will also have the :value key
Second line deletes element from array by content. You need to know error message. Use the right locale key value
Just came across this, you can do model.errors.clear

Is there an easier way to persist an object to db when using angular-meteor?

I really like meteor-angular, however, in the following code snippet, I think there is still friction when persisting changes back to the db. For example, in this code sample:
saveParty(name: string, description: string) {
Parties.update(this.selectedParty._id, {$set: {name: name, description: description}});
}
it is going to difficult to manually type "name: name, description: description" if there were a large number of fields.
Is it possible to do something like (kind of like what breezsjs does):
saveParty() {
Parties.save(this.selectedParty);
}
or better yet:
saveParty() {
this.selectedParty.Save();
}
Yes :)
Take a look at AngularMeteorCollection methods here - http://angular-meteor.com/api/AngularMeteorCollection#methods
AngularMeteorObject methods here - http://angular-meteor.com/api/AngularMeteorObject
and
And the examples at the bottom

MongoDB Ruby driver typecasting while inserting document

While creating a document that is got from web interface, it does not rightly typecast integer date and other type. for example
{"_id": "<some_object_id>", "name": "hello", "age": "20", "dob": "1994-02-22"}
Since attributes are entered dynamically, their types can not be prejudged. Is there any way I can get them entered from client side, like
{"_id": "<some_object_id>", "name": "hello", "age": "$int:20", "dob": "$date:1994-02-22"}
Any help is highly appreciated.
Since you appear to be concerned about the strings that come in from a form such as a POST, the simple answer is that you cast them in Ruby.
If the field is what you expect to be a number then cast it to an int. And the same goes for dates as well.
Your mongo driver will correctly interpret these and store them as the corresponding BSON types in your MongoDB collection. The same goes in reverse, when you read collection data you will get it back cast into your native types.
"1234".to_i
Date.strptime("{ 2014, 2, 22 }", "{ %Y, %m, %d }")
But that's be basic Ruby part.
Now you could do something like you pseudo-suggested and store your information, not as native types but as strings with some form of type tagging. But see, I just don't see the point as you would have to
Detect the type at some stage and apply the tag
Live with the fact that you just ruined all the benefits of having the native types in the collection. Such as query and aggregation for date ranges and basic summing of values.
And while we seem to be going down the track of the anything type where users just arbitrarily insert data and something else has to work out what type it is, consider the following examples of MongoDB documents:
{
name: "Fred",
values: [ 1, 2, 3, 4],
}
{
name: "Sally",
values: "a"
}
So in Mongo terminology, that document structure is considered bad. Even though Mongo does have a flexible schema concept, this type of mixing will break things. So don't do it, but rather handle in the following way, which is quite acceptable even though the schema's are different:
{
name: "Fred",
values: [ 1, 2, 3, 4],
}
{
name: "Sally",
mystring: "a"
}
The long story short, Your application should be aware of the types of data that are coming in. If you allow user defined forms then your app needs to be able to attach a type to them. If you have a field that could be a string or a Date, then your app need to determine which type it is, and cast it, or otherwise store it correctly.
As it stands you will benefit from re-considering you use case, rather than waiting for something else to work all that out for you.

how to convert string to integer when I try to access the data in json converted to hash in ruby?

I have converted the data in json to a hash and tried to access the data. I used the following code:
require 'yajl'
json=File.new('5104.txt', 'r')
parser=Yajl::Parser.new
hash=parser.parse(json)
puts hash['response']['venue']['id']
puts hash['response']['venue']['name']
puts hash['response']['venue']['categories']['parents']
When I run this code, I had this error message says:
test.rb:8:in `[]': can't convert String into Integer (TypeError)
from test.rb:8:in `<main>'
I assume it means that the data type of 'parents' is string which cannot be converted to integer. Does anyone know how should I solve this problem? Is there anyway I can convert this string into integer and save it?
Thanks ahead and I really appreciate your help.
Thanks a lot for your answers. Line 8 is the last line for 'parents'. I can use this code to get 'id' and 'name', but cannot get the data for 'parent'. Here is the json;
response: {
venue: {
id: "xxx"
name: "xxx"
contact: {
phone: "xxx"
formattedPhone: "xxx"
twitter: "theram"
}
location: {
address: "xxx"
lat: xxx
lng: xxx
postalCode: "xxx"
city: "xxx"
state: "xxx"
country: "xxx"
}
categories: [
{
id: "xxx"
name: "xxx"
pluralName: "xxx"
shortName: "xxx"
icon: "xxx"
parents: [
"xxx"
]
primary: true
}
]
}
}
I converted the json to a hash. If it is the case that this json is an array which requires integers for its keys, is there anyway that I can convert this string into an integer so that I can still use this code to get the data I want? If not, is there any other ways that I can get data for 'parents'? Regular expression?
Thanks ahead :)
Categories is an array, you should get an item before trying to get the parents:
hash['response']['venue']['categories'].first['parents']
There's also a primary parameter, if there could be more than one category and want to get the primary one, use Array#select:
hash['response']['venue']['categories'].select {|category| category['primary'] } .first['parents']
Are you absolutely positive that what you're getting out of the JSON is a hash? Because that error message generally means you're trying to access an array with a non-integer key.
I'm guessing that your JSON is actually an array, and ruby is dutifully complaining that you're not treating it like one.

Resources