Code Monkey home page Code Monkey logo

json-flattener's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

json-flattener's Issues

Using '_' as a separator results in malformed result.

Input = "{"bean":{"hostname":"e46e98985","name":"898898de5","version":"5.5"},"input_type":"log","message":{"sensor_id":"p02","ts":1.519776762821703E9,"uid":"CVfeCHDFIFIfXSTcj","id_orig_h":"10.10.10.10"

output = {"bean_hostname":"e46e98985","bean_name":"e46e98985","bean_version":"5.5","[\"input_type\"]:"log","message[\"sensor_id\"]":"p02","message_ts":1519776762.821703,"message_uid":"CVfeCHDFIFIfXSTcj","message[\"id_orig_h\"]":"10.10.10.10",

It looks like values with '_ ' characters throw off the parser and it escapes the value and wraps it in brackets.

Any ideas on how to fix this. I tried a few other characters and they work fine.

issue with flattening json schema containing patternProperties regex

It seems that the key for a flattened patternProperties gets mangled as with the one herein:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "KeyMap": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "characteristicsFilters": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/definitions/CharacteristicsFilter"
          }
        }
      },
      "required": ["characteristicsFilters"],
      "title": "KeyMap"
    },
    "CharacteristicsFilter": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "filterName": {
          "type": "string"
        },
        "values": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string",
            "patternProperties": { "^[A-Za-z0-9 -_]+$" : {} }
          }
        }
      },
      "required": [
        "filterName",
        "values"
      ],
      "title": "CharacteristicsFilter"
    }
  },

  "title": "KeyMap",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "keyMap": { "$ref": "#/definitions/KeyMap" }
  },
  "required": ["keyMap"]
}

custom separator option?

Hello,
thnx for nice lib.
I'm using json flattening in Ruby and Java projects so that both could provide same-looking json for elasticsearch. dot-separator is a bad idea for us and ELK, in ruby gem flat_keys there is an option to set custom separator, but this lib misses it. Can it be added please?
I'll try to make a pull request.

KEEP_ARRAYS StackOverflow

The test case added to PR #8 breaks version 0.2.0
test4.json on the PR

{
  "a": {
    "b": 1,
    "c": null,
    "d": [false, {
      "i": {
        "j": [false, true]
      }
    }]
  },
  "e": "f",
  "g": 2.3,
  "z": []
}

Unflatten code is very slow compared to Flatten

Hi,

I tries to test with a Json of 25kb. I integrated this code with my service which almost becomes slow by 20 ms.

I tries to make a sample code in which flatten and unfaltten is done.

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.wnameless.json.flattener.JsonFlattener;
import com.github.wnameless.json.unflattener.JsonUnflattener;

public class Test {

public static void main(String[] args) {

String a = "{\"r_id\":\"235d6ad9-8ff3-400c-a67e-c7b1c38e1318\",\"cid\":47,\"plc\":[{\"id\":98,\"cn\":\"Does the Mobile Switch on111?\",\"st\":\"Should be able to make and receive calls\",\"plo\":1,\"plp\":[{\"required\":true,\"pid\":371,\"en\":\"mobileSwitchOn\",\"pl\":\"Are you able to make and receive c2a333?\",\"ht\":\"Mobile Switch On\",\"pt\":406,\"sl\":false,\"vt\":\"Please Select Gadget Condition\",\"po\":200,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":true,\"pvr\":[{\"id\":3009,\"vl\":\"Mobile Switches On\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":1,\"pmt\":\"\",\"vgn\":\"Yes\"},{\"id\":3010,\"vl\":\"Mobile Doesn't Switch On\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":5,\"pmt\":\"\",\"vgn\":\"No\"},{\"id\":3011,\"vl\":\"Not \\nTested\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":10,\"pmt\":\"\"}],\"gl\":\"Device Details\"}],\"pmt\":\"\"},{\"id\":99,\"cn\":\"Screen Condition\",\"st\":\"Choose appropriate option as per your screen condition\",\"plo\":2,\"plp\":[{\"required\":true,\"pid\":372,\"en\":\"screenTouchCalibration\",\"pl\":\"Is your device's touch screen working properly?\",\"ht\":\"Check the touch screen of your phone\",\"pt\":9,\"sl\":true,\"vt\":\"Please select touch condition\",\"po\":2,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":true,\"pvr\":[{\"id\":3013,\"vl\":\"Touch Faulty\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":1,\"pmt\":\"\",\"vgn\":\"No\"},{\"id\":3012,\"vl\":\"Touch Working\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":2,\"pmt\":\"\",\"vgn\":\"Yes\"}],\"gl\":\"Screen Condition\"},{\"required\":true,\"pid\":373,\"en\":\"screenDisplaySpot\",\"pl\":\"Dead Pixels/Spots on Screen\",\"ht\":\"Check your device's screen for visible spots\",\"pt\":1001,\"sl\":true,\"vt\":\"Please select condition for dead pixels/spots\",\"po\":3,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":true,\"pvr\":[{\"id\":3015,\"vl\":\"Minor discoloration or small spots on screen\",\"ht\":\"\",\"in\":\"5d24781e54727.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":3,\"pmt\":\"\"},{\"id\":3016,\"vl\":\"Multiple visible spots on screen\",\"ht\":\"\",\"in\":\"5d24787fc4526.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":2,\"pmt\":\"\"},{\"id\":3017,\"vl\":\"Large/ heavy visible spots on screen\",\"ht\":\"\",\"in\":\"5d2478e38355a.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":1,\"pmt\":\"\"},{\"id\":3018,\"vl\":\"No spots on screen\",\"ht\":\"\",\"in\":\"5d247941c2083.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":4,\"pmt\":\"\"}],\"gl\":\"Screen Condition\"},{\"required\":true,\"pid\":374,\"en\":\"screenDisplayLines\",\"pl\":\"Visible Lines on Screen\",\"ht\":\"Check your device's screen for visible lines\",\"pt\":1001,\"sl\":true,\"vt\":\"Please make selection for visible lines on screen\",\"po\":4,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":true,\"pvr\":[{\"id\":3020,\"vl\":\"Display faded along corners\",\"ht\":\"\",\"in\":\"5d247a3b90b41.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":1,\"pmt\":\"\"},{\"id\":3021,\"vl\":\"Multiple visible line(s) on Display\",\"ht\":\"\",\"in\":\"5d247a96cbe63.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":2,\"pmt\":\"\"},{\"id\":3022,\"vl\":\"No line(s) on Display\",\"ht\":\"\",\"in\":\"5d247b1500e0d.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":3,\"pmt\":\"\"}],\"gl\":\"Screen Condition\"},{\"required\":true,\"pid\":375,\"en\":\"screenPhysicalCondition\",\"pl\":\"Screen Physical Condition\",\"ht\":\"Check physical condition of Display Screen\",\"pt\":1001,\"sl\":true,\"vt\":\"Please select screen physical condition\",\"po\":5,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":true,\"pvr\":[{\"id\":3024,\"vl\":\"1-2 scratches on screen\",\"ht\":\"\",\"in\":\"5d248102de5a6.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":4,\"pmt\":\"\"},{\"id\":3025,\"vl\":\"Heavy scratches on screen\",\"ht\":\"\",\"in\":\"5d2480b3d5398.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":3,\"pmt\":\"\"},{\"id\":3026,\"vl\":\"Screen cracked/ glass broken\",\"ht\":\"\",\"in\":\"5d247f7a756cd.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":1,\"pmt\":\"\"},{\"id\":3589,\"vl\":\"Damaged/ Torn screen on edges\",\"ht\":\"\",\"in\":\"5d247ffbf0638.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":2,\"pmt\":\"\"},{\"id\":3027,\"vl\":\"No scratches on screen\",\"ht\":\"\",\"in\":\"5d2481565c62e.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":5,\"pmt\":\"\"}],\"gl\":\"Screen Condition\"},{\"required\":true,\"pid\":393,\"en\":\"overallScreenCondition\",\"pl\":\"2. Are there any problems with your mobile screen?\",\"ht\":\"Check your mobile screen for scratches, cracks, discoloration spots, lines or touch issues.\",\"pt\":9,\"sl\":true,\"vt\":\"Please answer the second question!\",\"po\":2,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":true,\"pvr\":[{\"id\":3081,\"vl\":\"Mobile Screen Flawless\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":176,\"pmt\":\"\",\"vgn\":\"No\"},{\"id\":3082,\"vl\":\"Mobile Screen Defective\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":174,\"pmt\":\"\",\"vgn\":\"Yes\"},{\"id\":3083,\"vl\":\"Not Tested\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":177,\"pmt\":\"\"}],\"gl\":\"Device Details\"}],\"pmt\":\"\"},{\"id\":100,\"cn\":\"Functional Problems\",\"st\":\"Choose appropriate option(s) to get accurate quote\",\"plo\":3,\"plp\":[{\"required\":false,\"pid\":376,\"en\":\"frontCamera\",\"in\":\"5a3caef2be5e5.png\",\"pl\":\"Front Camera not working\",\"ht\":\"Please select if front camera doesn't work properly\",\"pt\":1003,\"sl\":true,\"vt\":\"Front camera error\",\"po\":6,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":false,\"pvr\":[{\"id\":3029,\"vl\":\"Front \\nCamera Working Fine\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":50,\"pmt\":\"\"},{\"id\":3030,\"vl\":\"Front Camera not working\",\"ht\":\"\",\"in\":\"5d2440e1d4b31.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":52,\"pmt\":\"\"}],\"gl\":\"Functional Condition\"},{\"required\":false,\"pid\":377,\"en\":\"backCamera\",\"in\":\"5a3cb1f3547d8.png\",\"pl\":\"Back camera not working\",\"ht\":\"Please select if back camera doesn't work properly\",\"pt\":1003,\"sl\":true,\"vt\":\"Back Camera Condition\",\"po\":7,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":false,\"pvr\":[{\"id\":3032,\"vl\":\"Back Camera Working Fine\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":56,\"pmt\":\"\"},{\"id\":3033,\"vl\":\"Back Camera not working\",\"ht\":\"\",\"in\":\"5d2441a16cca9.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":60,\"pmt\":\"\"}],\"gl\":\"Functional Condition\"},{\"required\":false,\"pid\":379,\"en\":\"wifi\",\"in\":\"5a3cb28a72580.png\",\"pl\":\"WiFi not working\",\"ht\":\"Please select if mobile is having trouble connecting to Wi-Fi  network\",\"pt\":1003,\"sl\":true,\"vt\":\"na\",\"po\":9,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":false,\"pvr\":[{\"id\":3038,\"vl\":\"Wifi Working Fine\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":70,\"pmt\":\"\"},{\"id\":3039,\"vl\":\"WiFi not working\",\"ht\":\"\",\"in\":\"5d2442d22fa49.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":72,\"pmt\":\"\"},{\"id\":3040,\"vl\":\"Not Tested\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":74,\"pmt\":\"\"}],\"gl\":\"Functional Condition\"},{\"required\":false,\"pid\":382,\"en\":\"volumeButton\",\"in\":\"5a3cb224d64fd.png\",\"pl\":\"Volume button not working\",\"ht\":\"Please select if volume button doesn't work properly\",\"pt\":1003,\"sl\":true,\"vt\":\"Volume Button\",\"po\":7,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":false,\"pvr\":[{\"id\":3047,\"vl\":\"Volume Button Working Fine\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":88,\"pmt\":\"\"},{\"id\":3048,\"vl\":\"Volume Button not working\",\"ht\":\"\",\"in\":\"5d2443731c3db.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":90,\"pmt\":\"\"}],\"gl\":\"Functional Condition\"},{\"required\":false,\"pid\":384,\"en\":\"battery\",\"in\":\"5a3cb4391d9fc.png\",\"pl\":\"Battery not working\",\"ht\":\"Please select if battery has charging issues\",\"pt\":1003,\"sl\":true,\"vt\":\"Battery\",\"po\":10,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":false,\"pvr\":[{\"id\":3053,\"vl\":\"Battery Is Working Fine\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":100,\"pmt\":\"\"},{\"id\":3054,\"vl\":\"Battery not working\",\"ht\":\"\",\"in\":\"5d244621b86f8.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":102,\"pmt\":\"\"}],\"gl\":\"Functional Condition\"},{\"required\":false,\"pid\":385,\"en\":\"speaker\",\"in\":\"5a3cb5bbafe4a.png\",\"pl\":\"Speaker not working\",\"ht\":\"Please select if speaker doesn't work properly\",\"pt\":1003,\"sl\":true,\"vt\":\"Speaker\",\"po\":11,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":false,\"pvr\":[{\"id\":3056,\"vl\":\"No Issue With Speaker\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":106,\"pmt\":\"\"},{\"id\":3057,\"vl\":\"Speaker not working\",\"ht\":\"\",\"in\":\"5d244674ced62.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":108,\"pmt\":\"\"},{\"id\":3058,\"vl\":\"Not Tested\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":110,\"pmt\":\"\"}],\"gl\":\"Functional Condition\"},{\"required\":false,\"pid\":389,\"en\":\"fingerTouchSensor\",\"in\":\"5bf516b4d9584.png\",\"pl\":\"Finger Touch not working\",\"ht\":\"Please select if fingerprint sensor doesn't work properly\",\"pt\":1003,\"sl\":true,\"vt\":\"Finger Touch Sensor Condition\",\"po\":13,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":false,\"pvr\":[{\"id\":3068,\"vl\":\"Finger Touch Sensor OK\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":146,\"pmt\":\"\"},{\"id\":3069,\"vl\":\"Finger Touch not working\",\"ht\":\"\",\"in\":\"5d2444092bce8.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":148,\"pmt\":\"\"},{\"id\":3070,\"vl\":\"Finger Touch Sensor not \\navailable\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":150,\"pmt\":\"\"}],\"gl\":\"Functional Condition\"},{\"required\":false,\"pid\":399,\"en\":\"chargingPort\",\"in\":\"5a3cb3cfe8b8e.png\",\"pl\":\"Charging Port not working\",\"ht\":\"Please select if charging port doesn't work properly\",\"pt\":1003,\"sl\":true,\"vt\":\"Charging Port\",\"po\":15,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":false,\"pvr\":[{\"id\":3100,\"vl\":\"Charging Port Working Fine\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":210,\"pmt\":\"\"},{\"id\":3101,\"vl\":\"Charging Port not working\",\"ht\":\"\",\"in\":\"5d24486306b57.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":212,\"pmt\":\"\"}],\"gl\":\"Functional Condition\"},{\"required\":false,\"pid\":424,\"en\":\"powerButton\",\"in\":\"5a3cb2c72a543.png\",\"pl\":\"Power Button not working\",\"ht\":\"Please select if power button doesn't work properly\",\"pt\":1003,\"sl\":true,\"vt\":\"Power Button\",\"po\":13,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":false,\"pvr\":[{\"id\":3138,\"vl\":\"Power Button Working Fine\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":1,\"pmt\":\"\"},{\"id\":3139,\"vl\":\"Power Button not working\",\"ht\":\"\",\"in\":\"5d244762197f4.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":2,\"pmt\":\"\"}],\"gl\":\"Functional Condition\"},{\"required\":false,\"pid\":436,\"en\":\"faceSensor\",\"in\":\"5c506465730ab.png\",\"pl\":\"Face Sensor not working\",\"ht\":\"Please select if face sensor doesn't work properly\",\"pt\":1003,\"sl\":true,\"vt\":\"Face Sensor Condition\",\"po\":13,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":false,\"pvr\":[{\"id\":3612,\"vl\":\"Face Sensor OK\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":1,\"pmt\":\"\"},{\"id\":3613,\"vl\":\"Face Sensor not working\",\"ht\":\"\",\"in\":\"5d2448e9ec9d0.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":2,\"pmt\":\"\"}],\"gl\":\"Functional Condition\"},{\"required\":false,\"pid\":469,\"en\":\"ringSilentKey\",\"pl\":\"Silent Button not working\",\"ht\":\"Ring Silent Key\",\"pt\":1003,\"sl\":true,\"vt\":\"Ring Silent Key\",\"po\":0,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":false,\"pvr\":[{\"id\":3776,\"vl\":\"Ring Silent Key Working\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":1,\"pmt\":\"\"},{\"id\":3777,\"vl\":\"Silent Button not working\",\"ht\":\"Ring Silent Key Not Working\",\"in\":\"5df0e69829e5c.png\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":2,\"pmt\":\"\"}],\"gl\":\"Functional Condition\"},{\"required\":false,\"pid\":470,\"en\":\"audioIC\",\"in\":\"5df9b5a9a557e.png\",\"pl\":\"Audio Receiver not working\",\"ht\":\"Audio IC\",\"pt\":1003,\"sl\":true,\"vt\":\"Audio IC\",\"po\":0,\"pmt\":\"0\",\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":false,\"pvr\":[{\"id\":3778,\"vl\":\"Audio IC Working\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":1,\"pmt\":\"\"},{\"id\":3779,\"vl\":\"Audio Receiver not working\",\"ht\":\"\",\"in\":\"5dfb2607b7889.png\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":5,\"pmt\":\"\"}],\"gl\":\"Functional Condition\"}],\"pmt\":\"\"},{\"id\":101,\"cn\":\"Do you have the following?\",\"st\":\"Select accessories which are available\",\"plo\":4,\"plp\":[{\"required\":false,\"pid\":400,\"en\":\"earphones\",\"in\":\"5a3cb4c61434c.png\",\"pl\":\"Earphones\",\"ht\":\"Earphones\",\"pt\":1002,\"sl\":true,\"vt\":\"Earphones Condition\",\"po\":16,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":false,\"pvr\":[{\"id\":3103,\"vl\":\"Original Earphones\",\"ht\":\"\",\"in\":\"5d2449ca64a06.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":216,\"pmt\":\"\"},{\"id\":3104,\"vl\":\"Earphones \\nNot available\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":218,\"pmt\":\"\"}],\"gl\":\"Do you have the following?\"},{\"required\":false,\"pid\":401,\"en\":\"validBill\",\"in\":\"5a3cb566f18b5.png\",\"pl\":\"Valid Bill\",\"ht\":\"Valid Bill\",\"pt\":1002,\"sl\":true,\"vt\":\"Valid Bill\",\"po\":19,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":false,\"pvr\":[{\"id\":3106,\"vl\":\"Bill with same \\nIMEI\",\"ht\":\"\",\"in\":\"5d244b19aa676.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":220,\"pmt\":\"\"},{\"id\":3107,\"vl\":\"Valid Bill Not Available\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":222,\"pmt\":\"\"}],\"gl\":\"Do you have the following?\"},{\"required\":false,\"pid\":402,\"en\":\"charger\",\"in\":\"5a3cb493dfbb9.png\",\"pl\":\"Original Charger\",\"ht\":\"Charger\",\"pt\":1002,\"sl\":true,\"vt\":\"Charger\",\"po\":17,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":false,\"pvr\":[{\"id\":3109,\"vl\":\"Original Charger of Device\",\"ht\":\"\",\"in\":\"5d244a8299b93.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":226,\"pmt\":\"\"},{\"id\":3110,\"vl\":\"Charger Not Available\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":228,\"pmt\":\"\"},{\"id\":3111,\"vl\":\"Charger Available But Not \\nOriginal\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":230,\"pmt\":\"\"}],\"gl\":\"Do you have the following?\"},{\"required\":false,\"pid\":403,\"en\":\"box\",\"in\":\"5a3cb531873f1.png\",\"pl\":\"Box\",\"ht\":\"Box\",\"pt\":1002,\"sl\":true,\"vt\":\"Box\",\"po\":18,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":false,\"pvr\":[{\"id\":3113,\"vl\":\"Box with same IMEI\",\"ht\":\"\",\"in\":\"5d244b6c82230.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":234,\"pmt\":\"\"},{\"id\":3114,\"vl\":\"Box Not Available\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":236,\"pmt\":\"\"}],\"gl\":\"Do you have the following?\"}],\"pmt\":\"\"},{\"id\":102,\"cn\":\"Mobile Age\",\"st\":\"Valid Bill mandatory for in-warranty device\",\"plo\":5,\"plp\":[{\"required\":true,\"pid\":404,\"en\":\"mobileAge\",\"pl\":\"Mobile Age\",\"ht\":\"Valid bill mandatory for in-warranty \\ndevice\",\"pt\":404,\"sl\":true,\"vt\":\"Please select Age of your Device\",\"po\":20,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ed\":{\"stm\":1581016289477000,\"etm\":1581331649477000},\"ir\":true,\"pvr\":[{\"id\":3116,\"vl\":\"Below 3 months\",\"ht\":\"Valid bill mandatory\",\"in\":\"5a3ca8d4ba927.png\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":1,\"pmt\":\"\"},{\"id\":3117,\"vl\":\"3 months - 6 months\",\"ht\":\"Valid bill mandatory\",\"in\":\"5a3ca90f2a4b0.png\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":2,\"pmt\":\"\"},{\"id\":3118,\"vl\":\"6 months - 11 months\",\"ht\":\"Valid bill \\nmandatory\",\"in\":\"5a3ca94276c76.png\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":3,\"pmt\":\"\"},{\"id\":3119,\"vl\":\"Above 11 months\",\"ht\":\"\",\"in\":\"5a3ca9820d8d3.png\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":4,\"pmt\":\"\"}],\"gl\":\"Mobile Age\"}],\"pmt\":\"\"},{\"id\":104,\"cn\":\"Is your mobile under warranty?\",\"st\":\"Warranty not applicable if device parts replaced/repaired at an unauthorized service center\",\"plo\":7,\"plp\":[{\"required\":true,\"pid\":405,\"en\":\"mobileWarranty\",\"pl\":\"4. Is your Mobile under warranty?\",\"ht\":\"You can get a better price for your device, if it's under warranty. Note: Please provide valid bill of your device.\",\"pt\":9,\"sl\":true,\"vt\":\"Please answer the fourth question!\",\"po\":21,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":true,\"pvr\":[{\"id\":3121,\"vl\":\"Mobile Under Warranty\",\"ht\":\"\",\"in\":\"58c114f66869b.png\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":250,\"pmt\":\"\",\"vgn\":\"Yes\"},{\"id\":3122,\"vl\":\"Mobile Out of Warranty\",\"ht\":\"\",\"in\":\"58c1157a0bd23.png\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":252,\"pmt\":\"\",\"vgn\":\"No\"}],\"gl\":\"Device Details\"}],\"pmt\":\"\"},{\"id\":105,\"cn\":\"Phone's Overall Condition\",\"st\":\"Choose appropriate options for phone's physical condition\",\"plo\":8,\"plp\":[{\"required\":true,\"pid\":395,\"en\":\"overallPhysicalCondition\",\"pl\":\"3. Are there any defects on your phone body?\",\"ht\":\"Check you device body (back & edges) for visible scratches and dents.\",\"pt\":9,\"sl\":true,\"vt\":\"Please answer the third question!\",\"po\":3,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":true,\"pvr\":[{\"id\":3087,\"vl\":\"Phone Body Flawless\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":186,\"pmt\":\"\",\"vgn\":\"No\"},{\"id\":3088,\"vl\":\"Phone Body Defective\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":184,\"pmt\":\"\",\"vgn\":\"Yes\"},{\"id\":3089,\"vl\":\"Not Tested\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":188,\"pmt\":\"\"}],\"gl\":\"Device Details\"},{\"required\":true,\"pid\":397,\"en\":\"simWorking\",\"pl\":\"1. Are you able to make and receive calls?\",\"ht\":\"Check your device for cellular network connectivity issues.\",\"pt\":9,\"sl\":true,\"vt\":\"Please answer the first question!\",\"po\":1,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":true,\"pvr\":[{\"id\":3093,\"vl\":\"Able to Make and Receive Calls\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":196,\"pmt\":\"\",\"vgn\":\"Yes\"},{\"id\":3094,\"vl\":\"Not Able to Make and Receive Calls\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":198,\"pmt\":\"\",\"vgn\":\"No\"},{\"id\":3095,\"vl\":\"Not Tested\",\"ht\":\"\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":200,\"pmt\":\"\"}],\"gl\":\"Device Details\"},{\"required\":true,\"pid\":429,\"en\":\"physicalConditionScratch\",\"pl\":\"Scratches on Phone Body\",\"ht\":\"Check for scratches on phone body\",\"pt\":1001,\"sl\":true,\"vt\":\"Please select condition for body scratches\",\"po\":190,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":true,\"pvr\":[{\"id\":3572,\"vl\":\"Less than 2 scratches\",\"ht\":\"\",\"in\":\"5d24843615469.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":2,\"pmt\":\"\"},{\"id\":3573,\"vl\":\"Major scratches\",\"ht\":\"\",\"in\":\"5d2483d9be1d2.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":1,\"pmt\":\"\"},{\"id\":3571,\"vl\":\"No scratches\",\"ht\":\"\",\"in\":\"5d24878e9cc5f.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":3,\"pmt\":\"\"}],\"gl\":\"Phone's Overall Condition\"},{\"required\":true,\"pid\":430,\"en\":\"physicalConditionDent\",\"pl\":\"Dents on Phone Body\",\"ht\":\"Check for dents on phone body\",\"pt\":1001,\"sl\":true,\"vt\":\"Please select condition for body dents\",\"po\":192,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":true,\"pvr\":[{\"id\":3576,\"vl\":\"2 or less minor body dents\",\"ht\":\"\",\"in\":\"5d24864c52234.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":2,\"pmt\":\"\"},{\"id\":3577,\"vl\":\"Multiple/heavy visible body dents\",\"ht\":\"\",\"in\":\"5d2485fc4b187.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":1,\"pmt\":\"\"},{\"id\":3575,\"vl\":\"No dents\",\"ht\":\"\",\"in\":\"5d248717d520d.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":3,\"pmt\":\"\"}],\"gl\":\"Phone's Overall Condition\"},{\"required\":true,\"pid\":431,\"en\":\"physicalConditionPanel\",\"pl\":\"Phone Side/Back Panel Condition\",\"ht\":\"Check your device's side & back panels\",\"pt\":1001,\"sl\":true,\"vt\":\"Please select panel condition\",\"po\":194,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":true,\"pvr\":[{\"id\":3579,\"vl\":\"Cracked/ broken side or back panel\",\"ht\":\"\",\"in\":\"5d2488726847c.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":1,\"pmt\":\"\"},{\"id\":3580,\"vl\":\"Missing side or back panel\",\"ht\":\"\",\"in\":\"5d2488c8d4b43.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":2,\"pmt\":\"\"},{\"id\":3587,\"vl\":\"No defect on side or back panel\",\"ht\":\"\",\"in\":\"5d248968c6aff.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":4,\"pmt\":\"\"}],\"gl\":\"Phone's Overall Condition\"},{\"required\":true,\"pid\":432,\"en\":\"physicalConditionBent\",\"pl\":\"Bent Phone or Loose Screen\",\"ht\":\"Check if your phone is bent or display screen is loose\",\"pt\":1001,\"sl\":true,\"vt\":\"Please select condition for bent phone\",\"po\":196,\"iu\":\"/cashify/productLinePart/\",\"cdn\":\"https://s3n.cashify.in\",\"ir\":true,\"pvr\":[{\"id\":3582,\"vl\":\"Bent/ curved panel\",\"ht\":\"\",\"in\":\"5d248a31e359a.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":1,\"pmt\":\"\"},{\"id\":3583,\"vl\":\"Loose screen (Gap in screen and body)\",\"ht\":\"\",\"in\":\"5d248ab00a5a0.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":3,\"pmt\":\"\"},{\"id\":3588,\"vl\":\"Phone not bent\",\"ht\":\"\",\"in\":\"5d248b1920a98.jpg\",\"iu\":\"/cashify/productLinePartVariation/\",\"p\":4,\"pmt\":\"\"}],\"gl\":\"Phone's Overall Condition\"}],\"pmt\":\"\"}],\"cfg\":[{\"pid\":410,\"vid\":3544},{\"pid\":411,\"vid\":3180},{\"pid\":412,\"vid\":3525},{\"pid\":413,\"vid\":3255},{\"pid\":414,\"vid\":3304},{\"pid\":415,\"vid\":3543},{\"pid\":416,\"vid\":3300},{\"pid\":417,\"vid\":3351},{\"pid\":418,\"vid\":3299},{\"pid\":419,\"vid\":3284},{\"pid\":420,\"vid\":3272},{\"pid\":422,\"vid\":3313},{\"pid\":425,\"vid\":3334},{\"pid\":426,\"vid\":3341},{\"pid\":435,\"vid\":3610},{\"pid\":437,\"vid\":3622},{\"pid\":471,\"vid\":3783},{\"pid\":472,\"vid\":3789}],\"r\":[{\"id\":164,\"pr\":10,\"exp\":\"((p.empty(p.getP('s'))) || (p.containsAny('3009',p.getP('s'))))\",\"img\":\"\",\"t\":\"Tell us a few things about your device!\",\"st\":\"What is the current condition of your device\",\"ht\":\"What is the current condition of your device\",\"pmt\":\"\",\"q\":[{\"eparam\":false,\"qid\":393,\"ep\":false,\"p\":20,\"vid\":[3081,3082]},{\"eparam\":false,\"qid\":395,\"ep\":false,\"p\":30,\"vid\":[3088,3087]},{\"eparam\":false,\"qid\":397,\"ep\":false,\"p\":10,\"vid\":[3093,3094]},{\"eparam\":false,\"qid\":405,\"ep\":false,\"p\":50,\"vid\":[3121,3122]}]},{\"id\":165,\"pr\":30,\"exp\":\"(p.containsAll('3082',p.getP('s')))\",\"img\":\"\",\"t\":\"Tell us more about your device's screen defects\",\"st\":\"(because you chose defective screen)\",\"ht\":\"Screen defect details\",\"pmt\":\"\",\"q\":[{\"eparam\":false,\"qid\":372,\"ep\":false,\"p\":10,\"vid\":[3012,3013]},{\"eparam\":false,\"qid\":373,\"ep\":false,\"p\":20,\"vid\":[3015,3016,3017,3018]},{\"eparam\":false,\"qid\":374,\"ep\":false,\"p\":30,\"vid\":[3020,3021,3022]},{\"eparam\":false,\"qid\":375,\"ep\":false,\"p\":40,\"vid\":[3024,3025,3026,3027,3589]}]},{\"id\":166,\"pr\":50,\"exp\":\"(p.containsAll('3088',p.getP('s')))\",\"img\":\"\",\"t\":\"Tell us more about your device's body defects\",\"st\":\"(Because you chose defective phone body)\",\"ht\":\"Body defect details\",\"pmt\":\"\",\"q\":[{\"eparam\":false,\"qid\":429,\"ep\":false,\"p\":10,\"vid\":[3573,3572,3571]},{\"eparam\":false,\"qid\":430,\"ep\":false,\"p\":20,\"vid\":[3577,3576,3575]},{\"eparam\":false,\"qid\":431,\"ep\":false,\"p\":30,\"vid\":[3580,3579,3587]},{\"eparam\":false,\"qid\":432,\"ep\":false,\"p\":40,\"vid\":[3582,3583,3588]}]},{\"id\":167,\"pr\":70,\"exp\":\"((p.containsAny('336|338|348|349|350|351|352|353|354|355|356|357|358|359|360|361|362|363|364|365|366|367|368|369|370|371|372|373|374|375|376|377|378|383|384|385|386|389|390|392|393|394|395|396|397',p.getP('b'))) && (!p.containsAny('20896|20897|20898|20854|20855|20865|20913|20914|20915|20926|20916|21463|21465|21888|21889|21890|21891|21892|21893|22355|22356|22357',p.getP('p'))))\",\"img\":\"\",\"t\":\"Do you have the following?\",\"st\":\"Please select accessories which are available\",\"ht\":\"Without earphone\",\"pmt\":\"\",\"q\":[{\"eparam\":false,\"qid\":402,\"ep\":false,\"p\":10,\"vid\":[3109]},{\"eparam\":false,\"qid\":403,\"ep\":false,\"p\":20,\"vid\":[3113]},{\"eparam\":false,\"qid\":401,\"ep\":false,\"p\":30,\"vid\":[3106]}]},{\"id\":168,\"pr\":60,\"exp\":\"(!p.empty(p.getP('s')))\",\"img\":\"\",\"t\":\"Functional or Physical Problems\",\"st\":\"Please choose appropriate condition to get accurate quote\",\"ht\":\"NA\",\"pmt\":\"\",\"q\":[{\"eparam\":false,\"qid\":376,\"ep\":false,\"p\":10,\"vid\":[3030]},{\"eparam\":false,\"qid\":377,\"ep\":false,\"p\":20,\"vid\":[3033]},{\"eparam\":false,\"qid\":379,\"ep\":false,\"p\":50,\"vid\":[3039]},{\"eparam\":false,\"qid\":382,\"ep\":false,\"p\":30,\"vid\":[3048]},{\"eparam\":false,\"qid\":384,\"ep\":false,\"p\":60,\"vid\":[3054]},{\"eparam\":false,\"qid\":385,\"ep\":false,\"p\":70,\"vid\":[3057]},{\"eparam\":false,\"qid\":389,\"ep\":false,\"p\":40,\"vid\":[3069]},{\"eparam\":false,\"qid\":399,\"ep\":false,\"p\":90,\"vid\":[3101]},{\"eparam\":false,\"qid\":424,\"ep\":false,\"p\":80,\"vid\":[3139]},{\"eparam\":false,\"qid\":436,\"ep\":false,\"p\":100,\"vid\":[3613]},{\"eparam\":false,\"qid\":469,\"ep\":false,\"p\":101,\"vid\":[3777]},{\"eparam\":false,\"qid\":470,\"ep\":false,\"p\":102,\"vid\":[3779]}]},{\"id\":169,\"pr\":100,\"exp\":\"((p.containsAll('3121',p.getP('s'))) && (p.containsAll('3106',p.getP('s'))) && (!p.containsAny('3013|3026|3582|3579|3580',p.getP('s'))) && (!p.containsAny('370',p.getP('b'))))\",\"img\":\"\",\"t\":\"What is your mobile age?\",\"st\":\"(Because you chose your device is under warranty)\",\"ht\":\"NA\",\"pmt\":\"\",\"q\":[{\"eparam\":false,\"qid\":404,\"ep\":false,\"p\":10,\"vid\":[3116,3117,3118,3119]}]},{\"id\":170,\"pr\":55,\"exp\":\"((p.getP('b') == 347) || ((p.getP('b') == 348) && (p.containsAny('20896|20897|20898|20854|20855|20865|20913|20914|20915|20926|20916|21463|21465|21889|21890|21888|21891|21892|22355|22356|22357|21893',p.getP('p')))))\",\"img\":\"\",\"t\":\"Do you have the following?\",\"st\":\"Please select accessories which are available\",\"ht\":\"With Earphone\",\"pmt\":\"\",\"q\":[{\"eparam\":false,\"qid\":400,\"ep\":false,\"p\":20,\"vid\":[3103]},{\"eparam\":false,\"qid\":402,\"ep\":false,\"p\":10,\"vid\":[3109]},{\"eparam\":false,\"qid\":403,\"ep\":false,\"p\":30,\"vid\":[3113]},{\"eparam\":false,\"qid\":401,\"ep\":false,\"p\":40,\"vid\":[3106]}]}],\"sp\":false,\"pid\":22470,\"plid\":44,\"bid\":347,\"isa\":1,\"imei_key\":\"imei\"}";
long now = System.currentTimeMillis();
ObjectMapper mapper = new ObjectMapper();
String x;
int b = 0;
for (int i = 1; i <= 1000; i++) {
  try {
    now = System.currentTimeMillis();
    String y = JsonFlattener.flatten(a);
    System.out.println(System.currentTimeMillis() - now);
    now = System.currentTimeMillis();
    JsonUnflattener.unflatten(y);
    System.out.println(System.currentTimeMillis() - now);
  } catch (Exception e) {
    e.printStackTrace();
  }
}
System.out.println(System.currentTimeMillis() - now);

}
}

Supporting a custom ObjectMapper

Supporting a custom ObjectMapper (e.g. .withMapper(ObjectMapper mapper)) in flatten or unflatten would allow the consumer of the class to define and pass in a mapper to use. It would be particularly useful because ObjectMappers can have custom modules and deserialization/serialization features set.

Forward slash in json key gets escaped on conversion

Hi,

I am using this library to flatten a nested json and it is very useful. I have one minor issue when the JSON key contains a forward slash, i.e. /.

For ex: "{\"user/id\":123}" on flattening becomes "{\"user\\/id\":123}".

Is there a way to prevent this and retain the actual key in the final output.

Thanks,
Mayank

Flattening the parent object

When flattening a model is it currently possible to provide an object parent level entry with the flattened object as the value?

So for an model like this:

{
  "object": {
    "id": 123,
    "name": "example"
  }
}

you get:

object             ->  { "id": 123, "name": "example" }
object.id          -> 123
object.name        -> "example"

Given that the intent is to flatten the model it would also be useful to be able to specify whether to convert it to a string.

object             ->  "{ \"id\": 123, \"name\": \"example\" }"
object.id          -> 123
object.name        -> "example"

Left and right bracket really have to be different?

Hi! Love your lib, it is really useful.

However, there is one thing: If I try the following, I get an error that the brackets are not allowed to be the same symbol

new JsonFlattener(line)
  .withLeftAndRightBrackets('#', '#')
  .withSeparator('_')
  .flattenAsMap()

Why is that? I can think of the brackets being the same character, which is just denoting some sort of separator.

It would be great if this could be supported in the next version, unless something speaks against it.

com.github.wnameless.json.flattener.JsonFlattener.jsonVal2Obj with double value as 0.0

Hi,
Below method is throwing number format Exception if the json value is "0.0" during jsonValue.asLong();

private Object jsonVal2Obj(JsonValue jsonValue) {
if (jsonValue.isBoolean()) return jsonValue.asBoolean();
if (jsonValue.isString()) return jsonValue.asString();
if (jsonValue.isNumber()) {
double v = jsonValue.asDouble();
if (!Double.isNaN(v) && !Double.isInfinite(v) && v == Math.rint(v))
return jsonValue.asLong();
else
return jsonValue.asDouble();
}

return null;

}

Embedded quotes are not escaped

I just started using you package and it creates invalid json when the value has embedded double quotes. I suspect there are other characters that need escaping as well. For example, I noticed all the forward slashes in my original json are escaped as well

Add support for nested objects unflattening with null container

I noticed that it is currently impossible to unflatten the following JSON:

"outer": null,
	"outer.inner": null

the outer object is null, so the following exception is thrown: java.lang.ClassCastException: class com.fasterxml.jackson.databind.node.NullNode cannot be cast to class com.fasterxml.jackson.databind.node.ObjectNode.

Obviously, the "outer.inner": null part has been added after the flattening process. I know that the unflattening feature isn't intended to be used with arbitrary JSONs, but there are circumstances where it would be useful (in my case, I'd like to add a nested object to a flattened JSON I receive, which sometimes lacks the outer object).

Issues while Trying to run the method

When trying to call the method, I am running into this error

Error (java.lang.NoClassDefFoundError)
org/apache/commons/text/translate/CharSequenceTranslator

I downloaded the latest jar file which is version 0.5.0

Thanks

Storing the nested JSON as one of the keys as well

This might be a very specific usecase, but would it be possible to also store the nested JSON inside of the Map that gets created in flattenAsMap.

What I mean is, if this is JSON:
{ "a":{ "b":1, "c":null, "d":[ false, true ] }, "e":"f", "g":2.3 }

Currently we already get {a.b=1, a.c=null, a.d[0]=false, a.d[1]=true, e=f, g=2.3}

I would also like to add a={
"b":1,
"c":null,
"d":[
false,
true
]
},
"e":"f",
"g":2.3
} and d=[
false,
true
]

where its stored as a String so every key will have a corresponding Object in the Map that gets created. Currently, 'a' doesn't have a key because it has nested objects so there is a.b, a.c, etc but not a.

Again, I realize it might not be useful for 99% of the people, but just thought I would throw it out there.

flatten() creates illegal json when input has null character

When input has a null character:

    String json = "{\"a\":\"b\\u0000c\"}";
    System.out.println("input: " + json);
    System.out.println("output: " + new JsonFlattener(json).flatten());

The output from flatten() is an illegal json:

    input: {"a":"b\u0000c"}
    output: {"a":"b�c"}

Parse Exception

I keep getting this error when I parse my file:

Exception in thread "main" com.eclipsesource.json.ParseException: Expected value at 1:0
at com.eclipsesource.json.JsonParser.error(JsonParser.java:379)
at com.eclipsesource.json.JsonParser.expected(JsonParser.java:372)
at com.eclipsesource.json.JsonParser.readValue(JsonParser.java:108)
at com.eclipsesource.json.JsonParser.parse(JsonParser.java:73)
at com.eclipsesource.json.Json.parse(Json.java:295)
at com.github.wnameless.json.flattener.JsonFlattener.(JsonFlattener.java:111)
at com.github.wnameless.json.flattener.JsonFlattener.flatten(JsonFlattener.java:80)
at Test.main(Test.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

The input I get is a new line delimited json, just an FYI

Add intermediary object to map

When calling flattenAsMap in the json
{ "a": { "b": 1, "c": null, "d": [false, true] }, "e": "f", "g": 2.3 }
i would like to get the result
{a={b=1, c=null, d[0]=false, d[1]=true, a.b=1, a.c=null, a.d[0]=false, a.d[1]=true, e=f, g=2.3}; with the a being one of the key of the map as well. Is it possible to do it today?

What is the key to search for when there is a period in the key?

I saw the EscapePolicy updates, but not sure if I am understanding it correctly.

If I have a json that looks something like

{
"test.v1": {
"_id": "test.v1"
}
}

On a flattenedJson where I have a Map<String, Object>
I would expect to be able to do something like

"test.v1._id" and value would be test.v1
In my logging of the set of keys though I see it wrapped in something else:

["test.v1"]._id is what the actual key is. How does this map to what I should be writing in String

Thanks

flatten+ merge + unflatten

Hi,

I am trying to flatten these 2 json combine then and unflatten them back but for some reason this error out
String data = "{\"_id\":{\"$oid\":\"5c80faf5563c541acb178ce2\"},\"display\":{\"rider\":false,\"customer\":false},\"tax\":{\"igst\":{\"percent\":0},\"sgst\":{\"percent\":0},\"cgst\":{\"percent\":0}},\"areaId\":null,\"active\":true,\"snooze\":false,\"serviceType\":\"delivery\",\"lyte\":false,\"platformCharges\":0,\"insuranceCharges\":0,\"cancelCharge\":0,\"cancelChargeTime\":0,\"extra\":0,\"createdBy\":{\"$oid\":\"59c3b272faf04e0b36e6aeba\"},\"createdOn\":1.55195672524E12,\"lastModifiedBy\":null,\"lastModifiedOn\":1.551955213555E12,\"timings\":[{\"_id\":{\"$oid\":\"5c80faf5563c541acb178ce9\"},\"from\":0,\"to\":2359,\"weekDay\":0,\"operational\":true},{\"_id\":{\"$oid\":\"5c80faf5563c541acb178ce8\"},\"from\":0,\"to\":2359,\"weekDay\":1,\"operational\":true},{\"_id\":{\"$oid\":\"5c80faf5563c541acb178ce7\"},\"from\":0,\"to\":2359,\"weekDay\":2,\"operational\":true},{\"_id\":{\"$oid\":\"5c80faf5563c541acb178ce6\"},\"from\":0,\"to\":2359,\"weekDay\":3,\"operational\":true},{\"_id\":{\"$oid\":\"5c80faf5563c541acb178ce5\"},\"from\":0,\"to\":2359,\"weekDay\":4,\"operational\":true},{\"_id\":{\"$oid\":\"5c80faf5563c541acb178ce4\"},\"from\":0,\"to\":2359,\"weekDay\":5,\"operational\":true},{\"_id\":{\"$oid\":\"5c80faf5563c541acb178ce3\"},\"from\":0,\"to\":2359,\"weekDay\":6,\"operational\":true}],\"lyteData\":{\"timings\":[]},\"priceWithKm\":[{\"kms\":100,\"price\":0}],\"city\":{\"$oid\":\"5a5f70a81635168040c9a163\"},\"baseFare\":0,\"minimumFare\":0,\"pricePerKm\":0,\"pricePerMinute\":0,\"rule\":\"0\",\"service\":{\"$oid\":\"58dcea3824565ce21202bca3\"},\"__v\":0,\"captain\":{\"regular\":{\"baseFare\":0,\"minimumFare\":0,\"pricePerMinute\":0,\"rule\":\"0\",\"priceWithKm\":[{\"kms\":100,\"price\":0}]}}} "

String sortedPatches = "{\"baseFare\":30,\"batchable\":false,\"captain\":{\"regular\":{\"baseFare\":0,\"minimumFare\":0,\"pricePerMinute\":0,\"rule\":\"0\",\"priceWithKm\":[{\"kms\":5,\"price\":0},{\"kms\":100,\"price\":0}]},\"batch\":{\"first\":{\"priceWithKm\":[]},\"next\":{\"priceWithKm\":[]}}},\"customer\":{\"batch\":{\"first\":{\"cancelCharge\":{\"ratePerKm\":[]},\"priceWithKm\":[]},\"next\":{\"cancelCharge\":{\"ratePerKm\":[]},\"priceWithKm\":[]}}},\"lastModifiedBy\":{\"$oid\":\"59c3b272faf04e0b36e6aeba\"},\"lastModifiedOn\":1.597231063793E12,\"minimumFare\":30,\"priceWithKm\":[{\"_id\":{\"$oid\":\"5f33cfd76e388d4ea5f570dc\"},\"kms\":5,\"price\":0},{\"_id\":{\"$oid\":\"5f33cfd76e388d7f57f570db\"},\"kms\":100,\"price\":4}],\"staticSurgeToCaptain\":false}";

error :

Exception in thread "main" java.lang.UnsupportedOperationException: Not an object: null
	at com.eclipsesource.json.JsonValue.asObject(JsonValue.java:290)
	at com.github.wnameless.json.unflattener.JsonUnflattener.setUnflattenedValue(JsonUnflattener.java:390)
	at com.github.wnameless.json.unflattener.JsonUnflattener.unflatten(JsonUnflattener.java:272)
	at com.github.wnameless.json.unflattener.JsonUnflattener.unflatten(JsonUnflattener.java:58)

Although both the json after unflattening indivisually look fine it is when i merge them and unflatten code errors out.

Mapping of timestamps

Hi,
is it possible to map Timestamp object to a date and not to number(millisecond)?

Support custom label handling for array indices?

Like we have withSeparator for nesting levels, can we have something similar for collection/array indices ?
string json = {key:[1,2,3]};
e.g. jsonflatterer.withInexSeparator('_').flat(json);

key_0 ,1 (instead of key[0] , 1)
key_1 ,2 (instead of key[1] , 2)
key_2 ,3 (instead of key[2] , 3)

Fail to Flatten Object with Field Key "root"

If there is a field called "root" anywhere in the JSON, it will not get flattened properly.

String json = "{"root":null}";
String flattened = new JsonFlattener(json).withSeparator('@').withFlattenMode(FlattenMode.KEEP_ARRAYS).flatten();
System.out.println(flattened);

flattenAsList

This repo helped me out a lot during my work today so here is my implementation for Object List flattening for your reference.

public static List<Map <String, Object>> flattenAsList(List<?> objects) {
    List<Map<String, Object>> rows = new ArrayList<>();
    for (int i=0; i<objects.size(); i++) { 
        rows.add(JsonFlattener.flattenAsMap(/* Object-to-Json Parsing */(objects.get(i)));
    }        
    return rows;
}

My full implementation using Ebean and FasterXml's Jackson (instead of EclipseResource Jsonvalue) is:

public static List<Map<String, Object>> flattenAsList(List<?> ebeans) throws JsonMappingException, IOException {
    List<Map<String, Objects>> rows = new ArrayList<>();
    for (int i=0; i<ebeans.size(); i++) {
        rows.add(JsonFlattener.flattenAsMap(Ebean.json().toJson(ebeans.get(i))));
    }
    return rows;
}

Support Java POJOs and custom map key labels using Annotations

Can we add some annotation support for Java pojos to map json keylabels to specific labels ?
e.g.
public class Test{

@ SomeAnnotation("myCustomLabel")
private Integer myField = 3;
}

JsonFlattener.flatten(new Test());
should produce Map with myCustomLabel, 3

Unflat no working with Mapobject

{"certificateAuthority" : {
"data" : "abcd"
}
}
Hi , using JsonUnflattener on json will provide --->
{
"certificateAuthority.data": "abcd"
}

but when you use JsonUnflattener on this flat result this an exception java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.node.ObjectNode.isEmpty()Z

on previous version this error message was different ("" is not an resource object")

Thanks

Issue in unflattening json

Issue while unflattening Json data:

When I tried this Json to unflatten using unflattening library,
it produces the following error :

Exception in thread "main" java.lang.UnsupportedOperationException:
Not an object: null

{
"course.List[5].type":"B",
"course.List[1].type":"C"
}

Denormalizing the Child with immediate parent

For example,

Input JSON - { "a": { "b": 1, "c": null, "d": [false, true] }, "e": "f", "g": 2.3 }
Flattened JSON - { "a.b": 1, "a.c": null, "a.d[0]": false, "a.d[1]": true, "e": "f", "g": 2.3 }

Is it possible to convert the above input JSON into the following structure ?

{"a.b": 1, "a:c": null, "e": "f", "g": 2.3}
{"a.b": 1, "a:c": null, "e": "f", "g": 2.3, "a.d": false}
{"a.b": 1, "a:c": null, "e": "f", "g": 2.3, "a.d": true}

array of objects does not support same key

String json = "{ "measurements" : { "name" : "fromState", "value": "AB", "name" : "toState","value": "BC"}}";
String flattenedJson = JsonFlattener.flatten(json);

Gives:

{"measurements.name":"toState","measurements.value":"BC"}

I expected to have both values included.

//mike

Slash in json value will prefix backslash after flatten

It's nice to have json flatten library.
Just notice that Apache NiFi 'FlattenJson' processor utilize this library to flat json.

Recently I've been working on some features update on this processor.
I noticed that if there is a slash at input json value.
Output will prefix every slash with a backslash .

For example,
input text:
{"innerClass":{},"col3":["http://localhost:8080/test1","http://localhost:8080/test2"]}
output text in dot notation:
{"innerClass":{},"col3[0]":"http://localhost:8080/test1","col3[1]":"http://localhost:8080/test2"}
(Message didn't show precisely in this text dialog there is actually backslash exist before slash)

Not sure if it's expected behavior.
But to me, it looks like data un-match problem.
This happens to all 3 flatten mode.

Please let me know your feedback.
Thanks.

Issue with empty json array .

While do the flatten this library removing empty json array if our input contain empty valued json array .So we are getting miss match data if we compare un flattened data with actual input .

Option to not flatten arrays

My use case wants to flatten the keys, but keep all values as they are. Could you please offer a configuration option to keep array values under the same key?

Getting stack overflow exception while parsing avro json format

I have avro json objects which I want to flatten in json. I have 16K objects to convert and i am able to convert few thousund but for some event it gives below stack trace.

Exception in thread "main" java.lang.StackOverflowError
at com.eclipsesource.json.WritingBuffer.write(WritingBuffer.java:51)
at com.eclipsesource.json.JsonWriter.writeObjectOpen(JsonWriter.java:77)
at com.eclipsesource.json.JsonObject.write(JsonObject.java:736)
at com.eclipsesource.json.JsonValue.writeTo(JsonValue.java:441)
at com.eclipsesource.json.JsonValue.toString(JsonValue.java:467)
at com.eclipsesource.json.JsonValue.toString(JsonValue.java:454)
at com.github.wnameless.json.flattener.JsonFlattener.jsonVal2Obj(JsonFlattener.java:263)
at com.github.wnameless.json.flattener.JsonFlattener.reduce(JsonFlattener.java:243)
at com.github.wnameless.json.flattener.JsonFlattener.flattenAsMap(JsonFlattener.java:208)
at com.github.wnameless.json.flattener.JsonFlattener.jsonVal2Obj(JsonFlattener.java:264)
at com.github.wnameless.json.flattener.JsonFlattener.reduce(JsonFlattener.java:243)
at com.github.wnameless.json.flattener.JsonFlattener.flattenAsMap(JsonFlattener.java:208)
at com.github.wnameless.json.flattener.JsonFlattener.jsonVal2Obj(JsonFlattener.java:264)
at com.github.wnameless.json.flattener.JsonFlattener.reduce(JsonFlattener.java:243)
at com.github.wnameless.json.flattener.JsonFlattener.flattenAsMap(JsonFlattener.java:208)
at com.github.wnameless.json.flattener.JsonFlattener.jsonVal2Obj(JsonFlattener.java:264)
at com.github.wnameless.json.flattener.JsonFlattener.reduce(JsonFlattener.java:243)
at com.github.wnameless.json.flattener.JsonFlattener.flattenAsMap(JsonFlattener.java:208)
at com.github.wnameless.json.flattener.JsonFlattener.jsonVal2Obj(JsonFlattener.java:264)
at com.github.wnameless.json.flattener.JsonFlattener.reduce(JsonFlattener.java:243)
at com.github.wnameless.json.flattener.JsonFlattener.flattenAsMap(JsonFlattener.java:208)
at com.github.wnameless.json.flattener.JsonFlattener.jsonVal2Obj(JsonFlattener.java:264)
at com.github.wnameless.json.flattener.JsonFlattener.reduce(JsonFlattener.java:243)
at com.github.wnameless.json.flattener.JsonFlattener.flattenAsMap(JsonFlattener.java:208)
at com.github.wnameless.json.flattener.JsonFlattener.jsonVal2Obj(JsonFlattener.java:264)
at com.github.wnameless.json.flattener.JsonFlattener.reduce(JsonFlattener.java:243)
at com.github.wnameless.json.flattener.JsonFlattener.flattenAsMap(JsonFlattener.java:208)
at com.github.wnameless.json.flattener.JsonFlattener.jsonVal2Obj(JsonFlattener.java:264)
at com.github.wnameless.json.flattener.JsonFlattener.reduce(JsonFlattener.java:243)
at com.github.wnameless.json.flattener.JsonFlattener.flattenAsMap(JsonFlattener.java:208)
at com.github.wnameless.json.flattener.JsonFlattener.jsonVal2Obj(JsonFlattener.java:264)
at com.github.wnameless.json.flattener.JsonFlattener.reduce(JsonFlattener.java:243)
at com.github.wnameless.json.flattener.JsonFlattener.flattenAsMap(JsonFlattener.java:208)
at com.github.wnameless.json.flattener.JsonFlattener.jsonVal2Obj(JsonFlattener.java:264)
at com.github.wnameless.json.flattener.JsonFlattener.reduce(JsonFlattener.java:243)
at com.github.wnameless.json.flattener.JsonFlattener.flattenAsMap(JsonFlattener.java:208)
at com.github.wnameless.json.flattener.JsonFlattener.jsonVal2Obj(JsonFlattener.java:264)
at com.github.wnameless.json.flattener.JsonFlattener.reduce(JsonFlattener.java:243)
at com.github.wnameless.json.flattener.JsonFlattener.flattenAsMap(JsonFlattener.java:208)
at com.github.wnameless.json.flattener.JsonFlattener.jsonVal2Obj(JsonFlattener.java:264)
at com.github.wnameless.json.flattener.JsonFlattener.reduce(JsonFlattener.java:243)
at com.github.wnameless.json.flattener.JsonFlattener.flattenAsMap(JsonFlattener.java:208)
at com.github.wnameless.json.flattener.JsonFlattener.jsonVal2Obj(JsonFlattener.java:264)
at com.github.wnameless.json.flattener.JsonFlattener.reduce(JsonFlattener.java:243)
at com.github.wnameless.json.flattener.JsonFlattener.flattenAsMap(JsonFlattener.java:208)
at com.github.wnameless.json.flattener.JsonFlattener.jsonVal2Obj(JsonFlattener.java:264)
at com.github.wnameless.json.flattener.JsonFlattener.reduce(JsonFlattener.java:243)
at com.github.wnameless.json.flattener.JsonFlattener.flattenAsMap(JsonFlattener.java:208)
at com.github.wnameless.json.flattener.JsonFlattener.jsonVal2Obj(JsonFlattener.java:264)
at com.github.wnameless.json.flattener.JsonFlattener.reduce(JsonFlattener.java:243)
at com.github.wnameless.json.flattener.JsonFlattener.flattenAsMap(JsonFlattener.java:208)
at com.github.wnameless.json.flattener.JsonFlattener.jsonVal2Obj(JsonFlattener.java:264)
at com.github.wnameless.json.flattener.JsonFlattener.reduce(JsonFlattener.java:243)
at com.github.wnameless.json.flattener.JsonFlattener.flattenAsMap(JsonFlattener.java:208)

grouping according to keys

is there a way such that we can group all the values for a key type into a list ?
for example consider the json below ⬇️

{"data":
[
{
    "Name": "crunchify.com",
    "Author": "App Shah",
    "Address": "New York"
},
{
    "Name": "crunchify.com",
    "Author": "App Shah",
    "Address": "New York"
}
]
}

the output is ⬇️

data[0].Address : New York
data[0].Author : App Shah
data[0].Name : crunchify.com
data[1].Address : New York
data[1].Author : App Shah
data[1].Name : crunchify.com

can i group the data into lists such as

Address = [New York , New York]
Author = [App Shah , App shah]
Name = [crunchify.com , crunchify.com]

Can we have getters on Point or PointBuilder class

Hi,

I use some generic code to parse json object to Point, we found it's difficult to verify the Point object after the parsing logic when we try to write test for the parsing. If we can have the Point's getters exposed, our life would be much easier.

Thanks
Alex

[Question] - how can I use json-flattener with JAX-RS?

I was wondering, what is the best method to override JAX default @javax.ws.rs.Consumes({MediaType.APPLICATION_JSON}) with json-flattener?

Maybe we could use a Jackson custom JsonSerializer? I am very new to Java so im not sure if that would be a feasible idea.

Thanks!

Missing Field in version 0.4.0

Its working fine with 0.1.0 version but somehow failing with 0.4.0 version.

Below is the stack trace :
Caused by: java.lang.NoSuchFieldError: ESCAPE_JSON
at com.github.wnameless.json.flattener.StringEscapePolicy.(StringEscapePolicy.java:46)
at com.github.wnameless.json.flattener.JsonFlattener.(JsonFlattener.java:109)
at com.github.wnameless.json.flattener.JsonFlattener.flatten(JsonFlattener.java:88)

[Bug] flattenAsMap produces escaped field names for field names that contain dot

Here's a code sample to demonstrate the issue.

public static void main(String[] args) throws Exception {
	final ObjectMapper mapper = new ObjectMapper();
	/*
	 * The input is just a simple json object { "a.b": 1 }
	 */
	final String jsonString = "{ \"a.b\": 1 }";
	final String flattenedString = JsonFlattener.flatten(jsonString);
	/*
	 * The following line prints
	 * {"[\"a.b\"]":1}
	 *
	 * No problem here.
	 */
	System.out.println(flattenedString);
	/*
	 * Print the only field name in the flattened json. It prints
	 * ["a.b"]
	 *
	 * No problem here either.
	 */
	System.out.println(mapper.readTree(flattenedString).fieldNames().next());
	final Map<String, Object> flattenedMap = JsonFlattener.flattenAsMap(jsonString);
	/*
	 * Print the only field name in the flattened map. It prints
	 * [\"a.b\"]
	 *
	 * And here's the problem. For some reason the quotes in the field name in the
	 * flattened map got unnecessarily escaped.
	 */
	System.out.println(flattenedMap.keySet().iterator().next());
	/*
	 * Just to confirm this, I'm parsing the map into json and printing the json.
	 * It prints
	 * {"[\\\"a.b\\\"]":1}
	 *
	 * So yes, the flattened map field name got unnecessarily escaped
	 */
	System.out.println(mapper.writeValueAsString(mapper.valueToTree(flattenedMap)));
}

So the gist of the issue is that, when you have a field name with a dot, the flatten method flattens things correctly, but flattenAsMap produces a Map with field names that got unnecessarily (and incorrectly) escaped.

Flattener.withSeparator breaking when nested JSON key has separator char in it.

Hi,

I was trying out the withSeparator functionality, turns out that it doesn't work correctly for few cases. Whenever we're using a separator and the nested JSON key has that separator, it breaks.

Eg. withSeparator('_')

Eg. {"a": 45, "b": {"c": "val"}}; // works fine in this case.
Output: {"a": 45, "b_c": "val"}

Eg. {"a": 45, "b": {"c_type": "val"}} // breaks since nested field c_type has an _ in it.
Output: {"a":45,"b["c_type"]":"val"}

This is the case whenever the separator char is present in one of the field key.

Getting stack overflow exception while parsing avro json format

Code :

import com.github.wnameless.json.flattener.FlattenMode;
import com.github.wnameless.json.flattener.JsonFlattener;

public class JsonFlattenStackOv {

public static void main(String[] args) {
    String event = "{\"header\": {\"eventUUID\": [-109, -5, 123, -37, -17, 50, 70, 52, -77, -121, -73, 13, 98, -80, 19, 72], \"timeEpochMillisUTC\": 1441251880803, \"clientId\": \"westernunion\", \"applicationId\": \"nemo-client-westernunion\", \"channel\": \"ONLINE\", \"eventType\": \"OnlineEvent\", \"associativeTag\": \"17aec40a-f14a-457d-a8ff-49bacd715327\", \"channelSessionId\": \"17aec40a-f14a-457d-a8ff-49bacd715327::1@@d8a3b43c-98aa-4c52-8f9c-e62cc03f0ead\", \"useInEvaluation\": true, \"optSequence\": 0, \"optSharedSessionId\": \"INT-sv1appin06-1441250243556-17374\", \"optAuthenticationToken\": null, \"optAPIRequestId\": null, \"environment\": \"PRODUCTION\"}, \"body\": {\"typeSpecificBody\": {\"body\": {}}, \"customProperties\": {\"TargetGroupId\": {\"value\": \"1010\"}, \"ClientTimestamp\": {\"value\": 1441251878657}, \"ScenarioId\": {\"value\": \"day0_feb5_chat_scn\"}, \"RuleId\": {\"value\": \"day0_feb5_cmpn:day0_feb5_chat_scn\"}, \"Queue\": {\"value\": \"westernunion-Western-Union-Queue\"}, \"Feedback\": {\"value\": \"\"}, \"InteractionCount\": {\"value\": \"\"}, \"RuleCategory\": {\"value\": \"p\"}, \"SubTennantId\": {\"value\": \"[\\\"western-union-sales\\\"]\"}, \"WidgetId\": {\"value\": \"8ac125d04bc0438f014bc07949e00004\"}, \"OptCampaignId\": {\"value\": \"day0_feb5_cmpn\"}, \"omniturevId\": {\"value\": \"\"}, \"AppInteractionId\": {\"value\": \"d8a3b43c-98aa-4c52-8f9c-e62cc03f0ead\"}, \"WidgetType\": {\"value\": \"CTA\"}}}}";
    String out = new JsonFlattener(event).withFlattenMode(FlattenMode.KEEP_ARRAYS).flatten();
    System.out.println(out);
}

}

asLong

Thanks for your work on this great library. It seems very useful.

However, I am having a problem...

My json looks like this (obfuscated):
{"39473331":{"mega":6.0,"goals":1.0}}

and I am getting this exception:

Caused by: java.lang.NumberFormatException: For input string: "6.0"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:589)
at com.eclipsesource.json.JsonNumber.asLong(JsonNumber.java:61)
at com.github.wnameless.json.flattener.JsonFlattener.jsonVal2Obj(JsonFlattener.java:174)

Now I was looking at your code and I've seen this here:

  double v = jsonValue.asDouble();
  if (!Double.isNaN(v) && !Double.isInfinite(v) && v == Math.rint(v))
    return jsonValue.asLong();
  else
    return jsonValue.asDouble();

Shouldn't it be the other way around? Like this:
if (!Double.isNaN(v) && !Double.isInfinite(v) && v == Math.rint(v))
return v;
else
return jsonValue.asLong();

In any case, it shouldn't try to parse 6.0 as a long.

performance of json flattener

Have you done any performance benchmark of this son flattener. When we ran it against a high volume json events stream to flatten, its taking significant time. I think it creates a lot of JsonFlatten object and the parser it uses is probably not the fastest.

Question: How to get index from a key when using JsonFlattener.flattenAsMap

Keys from Map are printed as [index].keyname. How to get the index value from keys?

Code:

Map<String, Object> flattenedJsonMap = JsonFlattener.flattenAsMap(response.readEntity(String.class));

Map<String,Object> keysMap = new HashMap<>();
flattenedJsonMap.forEach(
       (k, v) -> keysMap.put(k, v)
);

for (String kval : keysMap.keySet()) {
    if (kval.contains("paper_id")) {
           System.out.println("\nkval="+kval+"\n"+keysMap.get(kval));
    }
}

Sample output

kval=[3].paper_id
01e3b313e78a352593be2ff64927192af66619b5

kval=[1].paper_id
004f0f8bb66cf446678dc13cf2701feec4f36d76

kval=[2].paper_id
01d162d7fae6aaba8e6e60e563ef4c2fca7b0e18

Wanted to get the total or get the index values (1,2,3 etc) from key ([1].paper_id)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.