How to deserialize JSON into flat, Map-like structure?

You can do this to traverse the tree and keep track of how deep you are to figure out dot notation property names: import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ValueNode; import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import org.junit.Test; public class FlattenJson { String json = “{\n” + ” \”Port\”:\n” + … Read more

How Do I Make FLATTEN Work for Non-Contiguous Ranges?

Edit 7/4/22: ms365 now has introduced a function called VSTACK() and TOCOL() which allows for the the functionality that we were missing from GS’s FLATTEN() (and works even smoother) In your case the formula could become: =TOCOL(A1:D6,1) And that small formula (where the 2nd parameter tells the function to ignore empty cells) would replace everything … Read more

How to create an image from UILabel?

From: pulling an UIImage from a UITextView or UILabel gives white image. // iOS – (UIImage *)grabImage { // Create a “canvas” (image context) to draw in. UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, 0.0); // high res // Make the CALayer to draw in our “canvas”. [[self layer] renderInContext: UIGraphicsGetCurrentContext()]; // Fetch an UIImage of our “canvas”. UIImage *image … Read more

XML shredding via XSLT in Java

Here is a generic solution as requested: <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:output omit-xml-declaration=”yes” indent=”yes”/> <xsl:strip-space elements=”*”/> <xsl:param name=”pLeafNodes” select=”//Level-4″/> <xsl:template match=”https://stackoverflow.com/”> <t> <xsl:call-template name=”StructRepro”/> </t> </xsl:template> <xsl:template name=”StructRepro”> <xsl:param name=”pLeaves” select=”$pLeafNodes”/> <xsl:for-each select=”$pLeaves”> <xsl:apply-templates mode=”build” select=”/*”> <xsl:with-param name=”pChild” select=”.”/> <xsl:with-param name=”pLeaves” select=”$pLeaves”/> </xsl:apply-templates> </xsl:for-each> </xsl:template> <xsl:template mode=”build” match=”node()|@*”> <xsl:param name=”pChild”/> <xsl:param name=”pLeaves”/> <xsl:copy> <xsl:apply-templates mode=”build” select=”@*”/> … Read more

Flatten array with objects into 1 object

Use Object.assign: let merged = Object.assign(…arr); // ES6 (2015) syntax var merged = Object.assign.apply(Object, arr); // ES5 syntax Note that Object.assign is not yet implemented in many environment and you might need to polyfill it (either with core-js, another polyfill or using the polyfill on MDN). You mentioned lodash, so it’s worth pointing out it … Read more