I have a simple JSON:
{
"config": {
"option": {
"destination": ""
}
}
}
I read this JSON in PowerShell as
$flattended = Get-Content .\aboveJson.json | ConvertFrom-Json
I need to set the value of destination element to some value and then save it back to the same JSON or another JSON while retaining the structure. However, while reading the Nested object I see, PowerShell treated the option element differently and while saving with ConvertTo-Json, I see the output as "option": "#{destination=""}"
Could anyone please help and guide to any articles as to how PowerShell treats this data structure and what should be my way to handle the scenario ?
You shouldn't see this issue with your current example. However, the symptoms you see are due to the number of nested levels in your JSON structure. By default, the ConvertTo-Json command uses a default depth of 2. You can manually set this differently.
$flattened = Get-Content .\aboveJson.json | ConvertFrom-Json
$flattened.config.option.destination = 'new destination'
$flattened | ConvertTo-Json -Depth 10
I would like to know how I can access the elements of an array in mongo (version 3.0) by position, just as I would with $arrayElemAt in the newer versions.
UPDATED: I want to achieve the same of this example using mongodb 3.0:
Thank you very much.
In this case $arrayElementAt returns only one element from a given position. If you want to manipulate a chunk of items you want to return you should use $slice. Please check the link for more references: MongoDB $slice
{ $slice: 3 } //for the first 3
{ $slice: -3 } //for the last 3
{ $slice: 2, 3 } //for 3 elements after skiping the 2 frist
How to move the symbol euro from the front of the value to after it?
Example:
{{product.price | currency : "€"}} will produce € 12.00
but I would like 12.00 €
You don't have to hack the currency filter!
AngularJS has a great support for i18n/l10n. The currency filter uses the default currency symbol from the locale service and positions it based on the locale settings.
So it's all about supporting and setting the right locale.
<script src="i18n/angular-locale_de-de.js"></script>
If you are using npm or bower all locales are available via the angular-i18n package.
<span>{{ product.price | currency }}</span>
will now produce the following output:
65,95 €
Supporting multiple localizations
If you want to support multiple localizations be careful with the currency symbol as it changes to the default currency of the used locale. But 65,95 € are different to $65,95. Provide the currency symbol as parameter to be safe:
<span>{{ product.price | currency:'€' }}</span>
In de-de the output would still be 65,95 € but if the location is eg. en-us it would be €65.95 (which is despite some other sayings the correct format to display euro prices in English).
To learn more about angular and i18n/l10n refer to the developer guide.
You can't with the currency filter. You could write your own, or just use the number filter.
{{(produce.price | number:2) + "€"}}
use this trick.
<div>{{product.price | currency : '' }} €</div>
The solutions proposed are all dirty.
at first, the filter allow change symbol by add it as parameter:
{{product.price | currency : "€"}}
but the right way is localize your app as suggested by #Andreas
if you localize your app for example with italian locale setting (it-it) inside your app you need only invoke the filter to obtain the € sign.
{{product.price | currency }}
Italian locale setting put the Euro sign before the currency value.
You could change che locale value, or much better override them as proposed in the follow linked answer:
Why AngularJS currency filter formats negative numbers with parenthesis?
you could override the locale setting put your currency symbol (\u00A4) as a prefix or suffix for positive value and negative too.
app.config(['$provide', function($provide) {
$provide.decorator('$locale', ['$delegate', function($delegate) {
if($delegate.id == 'it-it') {
$delegate.NUMBER_FORMATS.PATTERNS[1].negPre = '\u00A4\u00a0-';
$delegate.NUMBER_FORMATS.PATTERNS[1].negSuf = '';
$delegate.NUMBER_FORMATS.PATTERNS[1].posPre = '\u00A4\u00a0';
$delegate.NUMBER_FORMATS.PATTERNS[1].posSuf = '';
}
return $delegate;
}]);
}]);
so after this instruction the filter:
{{product.price | currency}}
will produce the follow output
€ 12
Angularjs has a great support for internationalization and localization.
The application of internationalization and localization depends on the scope of your application.
For example if your application only support euro then you need only the localization for euro and does not require all the currency and its formatting.
In such situation (Assuming your situation is similar to above ) you can create an app configuration and set locale as the localization you required using some decorators. A decorator function intercepts the creation of a service, allowing it to override or modify the behavior of the service.
angular
.module('app', [])
.config(['$provide', function($provide) {
$provide.decorator('$locale', ['$delegate', function($delegate) {
$delegate.NUMBER_FORMATS = {
DECIMAL_SEP: '.',
GROUP_SEP: ',',
PATTERNS: [{ // Decimal Pattern
minInt: 1,
minFrac: 0,
maxFrac: 3,
posPre: '',
posSuf: '',
negPre: '-',
negSuf: '',
gSize: 3,
lgSize: 3
}, { //Currency Pattern
minInt: 1,
minFrac: 0,
maxFrac: 1,
posPre: '\u00A4',
posSuf: '',
negPre: '(\u00A4',
negSuf: ')',
gSize: 3,
lgSize: 3
}],
CURRENCY_SYM: '€'
}
return $delegate;
}]);
}])
.controller('appController', ['$scope', function($scope) {
$scope.price = 20.55;
}])
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.6/angular.min.js"></script>
<div ng-app="app">
<div ng-controller="appController">
Price : {{price | currency}}
</div>
</div>
The above configuration shows all possible values for decimal and currency settings.
You can change according to your requirements at app level.
If you dont want the effect to be in entire application better is to go for a directive
It's quite an old question, it's different these days.. Maybe it was back then aswell..
So if someone else finds this..
But you need to include the correct locale to get the correct currency formatting in the currency filter.
Check the angular documentation, for example dutch currency formatting is € 5,00 While english is 5,00 € and american is €5.00
I use this solution in my project (in production) in France (It must ALWAYS show 5.00€, NEVER show €5.00):
<span>Price: {{product.price| currency:""}} €</span>
DEMO
Please, read the real question of this post (Angular Js currency, symbol euro after) before downvote too quickly!!!!!
Using the locale (as explained in the answer in this thread -
at Angular Js currency, symbol euro after) seems like the most correct way to do it, but it doesn't seem to offer the flexibility to put the currency symbol or name where you want it relative to the value you're referencing to. If you need to have your currency symbol after your value, you could have a separate product.currency field and interpolate that after (or before) your price value.
So if you have product.price = 40 and product.currency = '€', you could display it as 40 € with {{product.price}} {{product.currency}}. Or € 40 by reversing the fields: {{product.currency}} {{product.price}}.
You'd probably want to format the product.price values via the decimal pipe if you did that (https://angular.io/api/common/DecimalPipe). - So "40.00 €" would be : {{product.amount | number:'2.2-2'}} {{product.currency}}.
fyi - in this case, I'd probably have a separate field product.currency and product.currencySymbol (e.g. "USD" and "$" respectively), but then you're getting more into the functionality of the locale as referenced in the other answer I link above. But if you need to place the currency name or symbol in a different location relative to the value than what Angular will let you do via its native pipes, and want to use a currency that's specific to a record or set that you're working with without hard-coding its symbol or name on the page (e.g. if you have multiple currencies you're displaying), this is one way to do it dynamically.
You can create a filter :
app.filter('euroFormat', function () {
return function (input) {
return input+' \u20AC';
};
});
and apply it on your html code with :
<span>Price: {{product.price| euroFormat}}</span>
I'm using Firebase to host enumerated values that describe various events, for example (man, I wish StackOverflow supported markdown tables):
| Enumeration | Description |
| ----------- | ----------- |
| 0 | A description of a low-priority event. |
| 1 | A description of a critical event. |
I'm storing that data in Firebase as follows:
"enumerations": {
"events": {
"0": {
"description": "A description of a low-priority event."
},
"1": {
"description": "A description of a critical event."
}
}
}
The plan is to have a user download the list of enumerations using the Firebase Rest API with both the ?print=pretty and ?download=filename request parameters, like so:
https://FIREBASE_NAME.firebaseio.com/enumerations/events.json?print=pretty&download=events.json
But the data that is received looks like the following:
[ {
"description": "A description of a low-priority event."
},
{
"description": "A description of a critical event."
} ]
Now, I know why this happens -
I've read the "Best Practices: Arrays in Firebase" article. I understand how Firebase interprets objects that look like arrays and then returns them as array, but, in my case I would really like a way to force Firebase to return a JSON object with numbered keys as they are stored in Firebase.
I'd like a solution that keeps the formatting of the table as is rather than naming the keys something like "event1", "event2", etc. Again, this is really only for the REST API, as it would be easy to do this in code, but this is for an external user to download directly from Firebase, so potentially having a URL request parameter ?forceAsArray=true would be a nice solution.
Or maybe I'm overlooking something in the documentation - Is this possible today?
I need to be able to show the currency dynamically with the value. For a fixed currency, I was able to do:
<span id="currency-custom">{{amount | currency:'₹'}}</span>
But what if I wanted to change the currency based on what came from the server as well? In my controller I have:
$scope.longestRide = {
'fromAddress': 'xxx',
'toAddress': 'yyy',
'mycurrency': '₹',
'cost': '238',
'duration': '00:49:02'
}
But this does not seem to work:
<span id="currency-custom">{{amount | currency:mycurrency}}</span>
How can I display the currency based on the javascript data structure?
You should try using your filter inside ng-bing-html like this:
<span ng-bind-html="amount | currency:mycurrency"></span>