question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug with passing custom separator while flattening nested object

See original GitHub issue

JsonFlattener.java:264 return new JsonFlattener(val.toString()).withFlattenMode(flattenMode).flattenAsMap(); is actually missing ‘.withSeparator(this.separator)’, and currently flattens nested object with default dot separator.

Mb there is similar issue for print mode, also for unflattener

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
wnamelesscommented, Oct 13, 2016

The issue has been fixed in version 0.2.3. Sorry for the late fix.

0reactions
glebstscommented, Aug 12, 2016

But this instance is created in JsonFlattener itself, which is supposed to be working dependency library 😃 I think we do not understand each other. I made a test which is a copy of existing separator test, but with existing test5.json payload. Do you see the difference in flattening ‘i’?

  @Test
  public void testWithSeparatorAndNestedObject() throws IOException {
    URL url = Resources.getResource("test5.json");
    String json = Resources.toString(url, Charsets.UTF_8);
    assertEquals(
        "{\"a_b\":1,\"a_c\":null,\"a_d\":[false,{\"i_j\":[false,true]}],\"e\":\"f\",\"g\":2.3,\"z\":{}}",
        new JsonFlattener(json).withFlattenMode(FlattenMode.KEEP_ARRAYS)
            .withSeparator('_')
            .flatten());
  }
org.junit.ComparisonFailure: 
Expected :{"a_b":1,"a_c":null,"a_d":[false,{"i_j":[false,true]}],"e":"f","g":2.3,"z":{}}
Actual   :{"a_b":1,"a_c":null,"a_d":[false,{"i.j":[false,true]}],"e":"f","g":2.3,"z":{}}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Fastest way to flatten / un-flatten nested JavaScript objects
Here's my much shorter implementation: Object.unflatten = function(data) { "use strict"; if (Object(data) !== data || Array.isArray(data)) return data; ...
Read more >
JavaScript: Flattening JSON with custom separator
In this tutorial we will learn how to use a custom separator when flattening a JavaScript object with the flat package.
Read more >
How to Flatten a Dictionary in Python in 4 Different Ways
In this post, we'll look at 4 different ways to flatten a dict in Python. For each method I'll point out the pros...
Read more >
The Serializer Component (Symfony Docs)
The Serializer component allows you to serialize and deserialize these objects using a "discriminator class mapping". The discriminator is the field (in the ......
Read more >
Reshaping JSON with jq - Programming Historian
When jq returns just one JSON object, the 'Compact Output' option will produce ... passing each answer on to the following filter operation....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found