json
Convert nested JSON array into separate columns in CSV file
2017-11-20, Completely rewrote function to improve performance and add features as -ArrayBase and support for PSStandardMembers and grouped objects. Flatten-Object Recursively flattens objects containing arrays, hash tables and (custom) objects. All added properties of the supplied objects will be aligned with the rest of the objects. Requires PowerShell version 2 or higher. Cmdlet Function Flatten-Object … Read more
With JSONDecoder in Swift 4, can missing keys use a default value instead of having to be optional properties?
You can implement the init(from decoder: Decoder) method in your type instead of using the default implementation: class MyCodable: Codable { var name: String = “Default Appleseed” required init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) if let name = try container.decodeIfPresent(String.self, forKey: .name) { self.name = name } } } You … Read more
Returning Null JSON Throwing Type Mismatch Error in VBA
Working with JSON files is much easier (IMHO) if you understand how the JsonConverter processes the JSON into a compound object. Let’s look at a simple JSON format (taken from this useful site): { “array”: [ 1, 2, 3 ], “boolean”: true, “null”: null, “number”: 123, “object”: { “a”: “b”, “c”: “d”, “e”: “f” }, … Read more
How to fetch JSON file in Angular 2
Here is a part of my code that parse JSON, it may be helpful for you: import { Component, Input } from ‘@angular/core’; import { Injectable } from ‘@angular/core’; import { Http, Response, Headers, RequestOptions } from ‘@angular/http’; import {Observable} from ‘rxjs/Rx’; import ‘rxjs/add/operator/map’; import ‘rxjs/add/operator/catch’; @Injectable() export class AppServices{ constructor(private http: Http) { var … Read more
Parsing JSON DateTime from Newtonsoft’s JSON Serializer
Use one of the JsonConverters that come with Json.NET for working with dates to get a better format. JavaScriptDateTimeConverter will automatically give you a JavaScript date. public class LogEntry { public string Details { get; set; } public DateTime LogDate { get; set; } } [Test] public void WriteJsonDates() { LogEntry entry = new LogEntry … Read more
How to parse JSON in Swift using NSURLSession
Don’t declare an AnyObject type for your decoded object since you want it to be an NSDictionary and you’re performing a conversion to do this. Also it’s better to use zero options for NSJSONSerialization instead of random ones. In my example I’ve also used a custom error type just for demonstration. Note, if you’re using … Read more
How to import JSON File into a TypeScript file?
Aonepathan’s one-liner was working for me until a recent typescript update. I found Jecelyn Yeen’s post which suggests posting this snippet into your TS Definition file add file typings.d.ts to the project’s root folder with below content declare module “*.json” { const value: any; export default value; } and then import your data like this: … Read more