How to call JSON filesystem structure in HTML file and javascript - filesystems
I have the following JSON file. I am wondering how can I call the files in the HTML file specially that there is a documents in some documents.
{
"d_type": "directory",
"name": ".",
"size": 1020,
"subdirectory": [
{
"d_type": "file",
"name": ".DS_Store",
"size": 15364
},
{
"d_type": "file",
"name": "animation.py",
"size": 928
},
{
"d_type": "file",
"name": "cat.png",
"size": 12574
},
{
"d_type": "file",
"name": "courses.json",
"size": 714
},
{
"d_type": "file",
"name": "courses.py",
"size": 827
},
{
"d_type": "file",
"name": "Courses.xlsx",
"size": 37894
},
{
"d_type": "file",
"name": "data.json",
"size": 356
},
{
"d_type": "file",
"name": "directoryTree.py",
"size": 452
},
{
"d_type": "file",
"name": "excelMani.py",
"size": 753
},
{
"d_type": "file",
"name": "exceltojson.py",
"size": 699
},
{
"d_type": "file",
"name": "filesystem.json",
"size": 0
},
{
"d_type": "file",
"name": "guess.py",
"size": 621
},
{
"d_type": "file",
"name": "hello.py",
"size": 107
},
{
"d_type": "file",
"name": "imtools.py",
"size": 115
},
{
"d_type": "file",
"name": "input.py",
"size": 184
},
{
"d_type": "file",
"name": "jsonFileOut.py",
"size": 705
},
{
"d_type": "file",
"name": "listFilesAndDirectories.py",
"size": 521
},
{
"d_type": "file",
"name": "memoryGame.py",
"size": 9368
},
{
"d_type": "file",
"name": "os.py",
"size": 156
},
{
"d_type": "file",
"name": "osout.py",
"size": 185
},
{
"d_type": "file",
"name": "output.json",
"size": 28816
},
{
"d_type": "file",
"name": "output.txt",
"size": 42385
},
{
"d_type": "file",
"name": "pygameDrawing.py",
"size": 1001
},
{
"d_type": "file",
"name": "pygameHello.py",
"size": 304
},
{
"d_type": "file",
"name": "rsa.py",
"size": 198
},
{
"d_type": "directory",
"name": "simplejson-3.6.5",
"size": 578,
"subdirectory": [
{
"d_type": "file",
"name": ".DS_Store",
"size": 12292
},
{
"d_type": "directory",
"name": "build",
"size": 170,
"subdirectory": [
{
"d_type": "directory",
"name": "bdist.macosx-10.9-intel",
"size": 68,
"subdirectory": []
},
{
"d_type": "directory",
"name": "lib.macosx-10.9-intel-2.7",
"size": 102,
"subdirectory": [
{
"d_type": "directory",
"name": "simplejson",
"size": 374,
"subdirectory": [
{
"d_type": "file",
"name": "__init__.py",
"size": 23137
},
{
"d_type": "file",
"name": "_speedups.so",
"size": 92976
},
{
"d_type": "file",
"name": "compat.py",
"size": 1036
},
{
"d_type": "file",
"name": "decoder.py",
"size": 14721
},
{
"d_type": "file",
"name": "encoder.py",
"size": 25280
},
{
"d_type": "file",
"name": "ordered_dict.py",
"size": 3370
},
{
"d_type": "file",
"name": "scanner.py",
"size": 4653
},
{
"d_type": "directory",
"name": "tests",
"size": 986,
"subdirectory": [
{
"d_type": "file",
"name": "__init__.py",
"size": 3029
},
{
"d_type": "file",
"name": "test_bigint_as_string.py",
"size": 2238
},
{
"d_type": "file",
"name": "test_bitsize_int_as_string.py",
"size": 2297
},
{
"d_type": "file",
"name": "test_check_circular.py",
"size": 917
},
{
"d_type": "file",
"name": "test_decimal.py",
"size": 2544
},
{
"d_type": "file",
"name": "test_decode.py",
"size": 4021
},
{
"d_type": "file",
"name": "test_default.py",
"size": 221
},
{
"d_type": "file",
"name": "test_dump.py",
"size": 4999
},
{
"d_type": "file",
"name": "test_encode_basestring_ascii.py",
"size": 2337
},
{
"d_type": "file",
"name": "test_encode_for_html.py",
"size": 1022
},
{
"d_type": "file",
"name": "test_errors.py",
"size": 1549
},
{
"d_type": "file",
"name": "test_fail.py",
"size": 6346
},
{
"d_type": "file",
"name": "test_float.py",
"size": 1430
},
{
"d_type": "file",
"name": "test_for_json.py",
"size": 2767
},
{
"d_type": "file",
"name": "test_indent.py",
"size": 2568
},
{
"d_type": "file",
"name": "test_item_sort_key.py",
"size": 1127
},
{
"d_type": "file",
"name": "test_namedtuple.py",
"size": 4004
},
{
"d_type": "file",
"name": "test_pass1.py",
"size": 1746
},
{
"d_type": "file",
"name": "test_pass2.py",
"size": 386
},
{
"d_type": "file",
"name": "test_pass3.py",
"size": 482
},
{
"d_type": "file",
"name": "test_recursion.py",
"size": 1679
},
{
"d_type": "file",
"name": "test_scanstring.py",
"size": 7311
},
{
"d_type": "file",
"name": "test_separators.py",
"size": 942
},
{
"d_type": "file",
"name": "test_speedups.py",
"size": 1011
},
{
"d_type": "file",
"name": "test_tool.py",
"size": 2853
},
{
"d_type": "file",
"name": "test_tuple.py",
"size": 1922
},
{
"d_type": "file",
"name": "test_unicode.py",
"size": 6996
}
]
},
{
"d_type": "file",
"name": "tool.py",
"size": 1136
}
]
}
]
},
{
"d_type": "directory",
"name": "temp.macosx-10.9-intel-2.7",
"size": 102,
"subdirectory": [
{
"d_type": "directory",
"name": "simplejson",
"size": 102,
"subdirectory": [
{
"d_type": "file",
"name": "_speedups.o",
"size": 268464
}
]
}
]
}
]
},
{
"d_type": "file",
"name": "CHANGES.txt",
"size": 17448
},
{
"d_type": "file",
"name": "conf.py",
"size": 5681
},
{
"d_type": "directory",
"name": "dist",
"size": 102,
"subdirectory": [
{
"d_type": "file",
"name": "simplejson-3.6.5-py2.7-macosx-10.9-intel.egg",
"size": 143523
}
]
},
{
"d_type": "file",
"name": "index.rst",
"size": 38920
},
{
"d_type": "file",
"name": "LICENSE.txt",
"size": 10375
},
{
"d_type": "file",
"name": "MANIFEST.in",
"size": 82
},
{
"d_type": "file",
"name": "PKG-INFO",
"size": 2735
},
{
"d_type": "file",
"name": "README.rst",
"size": 1412
},
{
"d_type": "directory",
"name": "scripts",
"size": 102,
"subdirectory": [
{
"d_type": "file",
"name": "make_docs.py",
"size": 420
}
]
},
{
"d_type": "file",
"name": "setup.cfg",
"size": 59
},
{
"d_type": "file",
"name": "setup.py",
"size": 3811
},
{
"d_type": "directory",
"name": "simplejson",
"size": 408,
"subdirectory": [
{
"d_type": "file",
"name": ".DS_Store",
"size": 6148
},
{
"d_type": "file",
"name": "__init__.py",
"size": 23137
},
{
"d_type": "file",
"name": "_speedups.c",
"size": 106976
},
{
"d_type": "file",
"name": "compat.py",
"size": 1036
},
{
"d_type": "file",
"name": "decoder.py",
"size": 14721
},
{
"d_type": "file",
"name": "encoder.py",
"size": 25280
},
{
"d_type": "file",
"name": "ordered_dict.py",
"size": 3370
},
{
"d_type": "file",
"name": "scanner.py",
"size": 4653
},
{
"d_type": "directory",
"name": "tests",
"size": 1020,
"subdirectory": [
{
"d_type": "file",
"name": ".DS_Store",
"size": 12292
},
{
"d_type": "file",
"name": "__init__.py",
"size": 3029
},
{
"d_type": "file",
"name": "test_bigint_as_string.py",
"size": 2238
},
{
"d_type": "file",
"name": "test_bitsize_int_as_string.py",
"size": 2297
},
{
"d_type": "file",
"name": "test_check_circular.py",
"size": 917
},
{
"d_type": "file",
"name": "test_decimal.py",
"size": 2544
},
{
"d_type": "file",
"name": "test_decode.py",
"size": 4021
},
{
"d_type": "file",
"name": "test_default.py",
"size": 221
},
{
"d_type": "file",
"name": "test_dump.py",
"size": 4999
},
{
"d_type": "file",
"name": "test_encode_basestring_ascii.py",
"size": 2337
},
{
"d_type": "file",
"name": "test_encode_for_html.py",
"size": 1022
},
{
"d_type": "file",
"name": "test_errors.py",
"size": 1549
},
{
"d_type": "file",
"name": "test_fail.py",
"size": 6346
},
{
"d_type": "file",
"name": "test_float.py",
"size": 1430
},
{
"d_type": "file",
"name": "test_for_json.py",
"size": 2767
},
{
"d_type": "file",
"name": "test_indent.py",
"size": 2568
},
{
"d_type": "file",
"name": "test_item_sort_key.py",
"size": 1127
},
{
"d_type": "file",
"name": "test_namedtuple.py",
"size": 4004
},
{
"d_type": "file",
"name": "test_pass1.py",
"size": 1746
},
{
"d_type": "file",
"name": "test_pass2.py",
"size": 386
},
{
"d_type": "file",
"name": "test_pass3.py",
"size": 482
},
{
"d_type": "file",
"name": "test_recursion.py",
"size": 1679
},
{
"d_type": "file",
"name": "test_scanstring.py",
"size": 7311
},
{
"d_type": "file",
"name": "test_separators.py",
"size": 942
},
{
"d_type": "file",
"name": "test_speedups.py",
"size": 1011
},
{
"d_type": "file",
"name": "test_tool.py",
"size": 2853
},
{
"d_type": "file",
"name": "test_tuple.py",
"size": 1922
},
{
"d_type": "file",
"name": "test_unicode.py",
"size": 6996
}
]
},
{
"d_type": "file",
"name": "tool.py",
"size": 1136
}
]
},
{
"d_type": "directory",
"name": "simplejson.egg-info",
"size": 204,
"subdirectory": [
{
"d_type": "file",
"name": "dependency_links.txt",
"size": 1
},
{
"d_type": "file",
"name": "PKG-INFO",
"size": 2735
},
{
"d_type": "file",
"name": "SOURCES.txt",
"size": 1357
},
{
"d_type": "file",
"name": "top_level.txt",
"size": 11
}
]
}
]
},
{
"d_type": "file",
"name": "test.xlsx",
"size": 34682
},
{
"d_type": "directory",
"name": "xlrd-0.9.3",
"size": 340,
"subdirectory": [
{
"d_type": "file",
"name": ".DS_Store",
"size": 6148
},
{
"d_type": "directory",
"name": "build",
"size": 136,
"subdirectory": [
{
"d_type": "directory",
"name": "lib",
"size": 102,
"subdirectory": [
{
"d_type": "directory",
"name": "xlrd",
"size": 476,
"subdirectory": [
{
"d_type": "file",
"name": "__init__.py",
"size": 21105
},
{
"d_type": "file",
"name": "biffh.py",
"size": 17511
},
{
"d_type": "file",
"name": "book.py",
"size": 56979
},
{
"d_type": "file",
"name": "compdoc.py",
"size": 21235
},
{
"d_type": "file",
"name": "formatting.py",
"size": 45335
},
{
"d_type": "file",
"name": "formula.py",
"size": 94301
},
{
"d_type": "file",
"name": "info.py",
"size": 22
},
{
"d_type": "file",
"name": "licences.py",
"size": 3406
},
{
"d_type": "file",
"name": "sheet.py",
"size": 107386
},
{
"d_type": "file",
"name": "timemachine.py",
"size": 1773
},
{
"d_type": "file",
"name": "xldate.py",
"size": 7895
},
{
"d_type": "file",
"name": "xlsx.py",
"size": 31809
}
]
}
]
},
{
"d_type": "directory",
"name": "scripts-2.7",
"size": 102,
"subdirectory": [
{
"d_type": "file",
"name": "runxlrd.py",
"size": 16300
}
]
}
]
},
{
"d_type": "file",
"name": "PKG-INFO",
"size": 994
},
{
"d_type": "file",
"name": "README.html",
"size": 4672
},
{
"d_type": "directory",
"name": "scripts",
"size": 102,
"subdirectory": [
{
"d_type": "file",
"name": "runxlrd.py",
"size": 16304
}
]
},
{
"d_type": "file",
"name": "setup.py",
"size": 1887
},
{
"d_type": "directory",
"name": "tests",
"size": 918,
"subdirectory": [
{
"d_type": "file",
"name": "__init__.py",
"size": 0
},
{
"d_type": "file",
"name": "base.py",
"size": 118
},
{
"d_type": "file",
"name": "Formate.xls",
"size": 10752
},
{
"d_type": "file",
"name": "formula_test_names.xls",
"size": 7680
},
{
"d_type": "file",
"name": "formula_test_sjmachin.xls",
"size": 16896
},
{
"d_type": "file",
"name": "issue20.xls",
"size": 6144
},
{
"d_type": "file",
"name": "merged_cells.xlsx",
"size": 9275
},
{
"d_type": "file",
"name": "picture_in_cell.xls",
"size": 6656
},
{
"d_type": "file",
"name": "profiles.xls",
"size": 33792
},
{
"d_type": "file",
"name": "ragged.xls",
"size": 6656
},
{
"d_type": "file",
"name": "reveng1.xlsx",
"size": 16683
},
{
"d_type": "file",
"name": "test_biffh.py",
"size": 574
},
{
"d_type": "file",
"name": "test_cell.py",
"size": 2328
},
{
"d_type": "file",
"name": "test_comments_excel.xlsx",
"size": 15803
},
{
"d_type": "file",
"name": "test_comments_gdocs.xlsx",
"size": 4187
},
{
"d_type": "file",
"name": "test_formats.py",
"size": 3039
},
{
"d_type": "file",
"name": "test_formulas.py",
"size": 2323
},
{
"d_type": "file",
"name": "test_open_workbook.py",
"size": 1294
},
{
"d_type": "file",
"name": "test_sheet.py",
"size": 4238
},
{
"d_type": "file",
"name": "test_workbook.py",
"size": 1483
},
{
"d_type": "file",
"name": "test_xldate.py",
"size": 2384
},
{
"d_type": "file",
"name": "test_xldate_to_datetime.py",
"size": 6128
},
{
"d_type": "file",
"name": "test_xlsx_comments.py",
"size": 1517
},
{
"d_type": "file",
"name": "text_bar.xlsx",
"size": 8196
},
{
"d_type": "file",
"name": "xf_class.xls",
"size": 23040
}
]
},
{
"d_type": "directory",
"name": "xlrd",
"size": 850,
"subdirectory": [
{
"d_type": "file",
"name": "__init__.py",
"size": 21105
},
{
"d_type": "file",
"name": "__init__.pyc",
"size": 3397
},
{
"d_type": "file",
"name": "biffh.py",
"size": 17511
},
{
"d_type": "file",
"name": "biffh.pyc",
"size": 15336
},
{
"d_type": "file",
"name": "book.py",
"size": 56979
},
{
"d_type": "file",
"name": "book.pyc",
"size": 37567
},
{
"d_type": "file",
"name": "compdoc.py",
"size": 21235
},
{
"d_type": "file",
"name": "compdoc.pyc",
"size": 13729
},
{
"d_type": "file",
"name": "xldate.pyc",
"size": 5654
},
{
"d_type": "file",
"name": "xlsx.py",
"size": 31809
}
]
}
]
}
]
}
Related
Pan and Zoom Tree in Vega
Looking to be able to Pan and Zoom a tree diagram in Vega. I have the example code working for my data but there is too much of it to be able to reasonably display in even a large chart. Therefore I am looking for a way to pan and zoom. I have searched Google and SO, but there are zero posts about panning and zooming a tree. Code used: "$schema": "https://vega.github.io/schema/vega/v5.json", "data": [ { "name": "default", "transform": [{ "type": "nest", "generate": true, "keys": ["$dimension1"] }, { "type": "tree", "method": "tidy", "size": [{"signal": "height"}, {"signal": "width - 20"}], "separation": true, "as": ["y", "x", "depth", "children"] } ] }, { "name": "links", "source": "default", "transform": [ { "type": "treelinks" }, { "type": "linkpath", "orient": "horizontal", "shape": "diagonal" } ] } ], "scales": [ { "name": "color", "type": "ordinal", "domain": {"data": "default", "field": "depth"}, "range": {"scheme": "datastudio20"} } ], "marks": [ { "type": "path", "from": {"data": "links"}, "encode": { "update": { "path": {"field": "path"}, "stroke": {"value": "#ccc"} } } }, { "type": "symbol", "from": {"data": "default"}, "encode": { "enter": { "size": {"value": 100}, "stroke": {"value": "#fff"} }, "update": { "x": {"field": "x"}, "y": {"field": "y"}, "fill": {"scale": "color", "field": "depth"} } } }, { "type": "text", "from": {"data": "default"}, "encode": { "enter": { "text": {"signal":"datum.$dimension0 || datum.key || 'Customer'"}, "fontSize": {"value": 12}, "baseline": {"value": "middle"} }, "update": { "x": {"field": "x"}, "y": {"field": "y"}, "dx": {"signal": "datum.children ? -7 : 7"}, "align": {"signal": "datum.children ? 'right' : 'left'"}, "opacity": 1 } } } ] }```
Here is an example for you: Editor { "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "An example of Cartesian layouts for a node-link diagram of hierarchical data.", "width": 600, "height": 600, "padding": 5, "autosize": {"type": "none", "resize": false}, "signals": [ { "name": "hover", "on": [ {"events": "*:mouseover", "encode": "hover"}, {"events": "*:mouseout", "encode": "leave"}, {"events": "*:mousedown", "encode": "select"}, {"events": "*:mouseup", "encode": "release"} ] }, {"name": "xrange", "update": "[0, width]"}, {"name": "yrange", "update": "[height, 0]"}, { "name": "down", "value": null, "on": [{"events": "mousedown", "update": "xy()"}] }, { "name": "xcur", "value": null, "on": [{"events": "mousedown", "update": "slice(xdom)"}] }, { "name": "ycur", "value": null, "on": [{"events": "mousedown", "update": "slice(ydom)"}] }, { "name": "delta", "value": [0, 0], "on": [ { "events": [ { "source": "window", "type": "mousemove", "consume": true, "between": [ {"type": "mousedown"}, {"source": "window", "type": "mouseup"} ] } ], "update": "down ? [down[0]-x(), y()-down[1]] : [0,0]" } ] }, { "name": "anchor", "value": [0, 0], "on": [ { "events": "wheel", "update": "[invert('xscale', x()), invert('yscale', y())]" } ] }, { "name": "zoom", "value": 1, "on": [ { "events": "wheel!", "force": true, "update": "pow(1.001, event.deltaY * pow(16, event.deltaMode))" } ] }, { "name": "xdom", "update": "slice(xext)", "on": [ { "events": {"signal": "delta"}, "update": "[xcur[0] + span(xcur) * delta[0] / width, xcur[1] + span(xcur) * delta[0] / width]" }, { "events": {"signal": "zoom"}, "update": "[anchor[0] + (xdom[0] - anchor[0]) * zoom, anchor[0] + (xdom[1] - anchor[0]) * zoom]" } ] }, { "name": "ydom", "update": "slice(yext)", "on": [ { "events": {"signal": "delta"}, "update": "[ycur[0] + span(ycur) * delta[1] / height, ycur[1] + span(ycur) * delta[1] / height]" }, { "events": {"signal": "zoom"}, "update": "[anchor[1] + (ydom[0] - anchor[1]) * zoom, anchor[1] + (ydom[1] - anchor[1]) * zoom]" } ] }, {"name": "size", "update": "clamp(20 / span(xdom), 1, 1000)"} ], "data": [ { "name": "tree", "url": "data/flare.json", "transform": [ {"type": "stratify", "key": "id", "parentKey": "parent"}, { "type": "tree", "method": {"signal": "'tidy'"}, "size": [{"signal": "height"}, {"signal": "width+100"}], "separation": {"signal": "true"}, "as": ["y", "x", "depth", "children"] }, {"type": "extent", "field": "x", "signal": "xext"}, {"type": "extent", "field": "y", "signal": "yext"} ] }, { "name": "links", "source": "tree", "transform": [ {"type": "treelinks", "signal": "upstream"}, { "type": "linkpath", "orient": "horizontal", "shape": {"signal": "'diagonal'"}, "sourceY": {"expr": "scale('yscale', datum.source.y)"}, "sourceX": {"expr": "scale('xscale', datum.source.x)"}, "targetY": {"expr": "scale('yscale', datum.target.y)"}, "targetX": {"expr": "scale('xscale', datum.target.x)"} } ] } ], "scales": [ { "name": "color", "type": "linear", "range": {"scheme": "magma"}, "domain": {"data": "tree", "field": "depth"}, "zero": true }, { "name": "xscale", "zero": false, "domain": {"signal": "xdom"}, "range": {"signal": "xrange"} }, { "name": "yscale", "zero": false, "domain": {"signal": "ydom"}, "range": {"signal": "yrange"} } ], "marks": [ { "type": "path", "from": {"data": "links"}, "encode": { "update": {"path": {"field": "path"}, "stroke": {"value": "#ccc"}} } }, { "type": "symbol", "from": {"data": "tree"}, "clip": true, "encode": { "enter": {"size": {"value": 100}, "stroke": {"value": "#fff"}}, "update": { "x": {"scale": "xscale", "field": "x"}, "y": {"scale": "yscale", "field": "y"}, "fill": {"scale": "color", "field": "depth"} } } }, { "type": "text", "from": {"data": "tree"}, "clip": true, "encode": { "enter": { "text": {"field": "name"}, "fontSize": {"value": 9}, "baseline": {"value": "middle"} }, "update": { "x": {"scale": "xscale", "field": "x"}, "y": {"scale": "yscale", "field": "y"}, "dx": {"signal": "datum.children ? -7 : 7"}, "align": {"signal": "datum.children ? 'right' : 'left'"}, "opacity": {"signal": "1"} } } } ] }
In Avro schema, how to wrap the array to an object and put it as a union instead of putting just array as union
I have the following data and I want to wrap the OPTIONAL array as an object and then put in as a union but since I am new to this, I am not sure how to do this. This is how I have done so far so could someone help me correct the below structure in the expected output. Note that this dataRefs is an optional field and this entire structure may or may not be present. { "name": "dataRefs", "default": null, "type": ["null", { "type": "array", "items": { "name": "dataRef", "type": "record", "fields": [ { "name": "dataId", "type": "string", "avro.java.string": "String" }, { "name": "email", "type": ["null" ,"string"], "avro.java.string": "String" }, { "name": "phone", "type": ["null" ,"string"], "avro.java.string": "String" }, { "name": "userName", "type": ["null" ,"string"], "avro.java.string": "String" }, { "name": "addressRef", "default": null, "type": ["null", { "name": "addressRefRecord", "type": "record", "fields": [ { "name": "addrRefId", "type": ["null","string"], "avro.java.string": "String" }, { "name": "addrType", "type": ["null","string"], "avro.java.string": "String" }, { "name": "addressLine1", "type": ["null","string"], "avro.java.string": "String" }, { "name": "addressLine2", "type": ["null","string"], "avro.java.string": "String" }, { "name": "city", "type": ["null","string"], "avro.java.string": "String" }, { "name": "province", "type": ["null","string"], "avro.java.string": "String" }, { "name": "country", "type": ["null","string"], "avro.java.string": "String" }, { "name": "postalCode", "type": ["null","string"], "avro.java.string": "String" } ] } ] } ] } } ] } My JSON data that I intend to map to above schema looks like follows: "dataRefs": [{ "addressRef": { "addrRefId": "0", "addrType": "ADDRESS", "addressLine1": "DA 81", "addressLine2": "", "city": "Amsterdam", "country": "Netherlands", "postalCode": "xxxx LN", "province": "" }, "dataId": "0", "email": "xyz#abc.com" }],
This is how I was able to do so: { "name": "dataRefs", "type": [ "null", { "type": "record", "name": "dataRefsObject", "fields": [ { "name": "dataRefsArray", "type": { "type": "array", "items": { "name": "dataRef", "type": "record", "fields": [ { "name": "dataId", "type": ["null", "string"], "avro.java.string": "String" }, { "name": "userName", "type": [ "null", "string" ], "avro.java.string": "String" }, ....
Accessing item in array of json object
The following is my json response from one of my APIs. I am trying to print image URL on console. You will see response is list of requests with each request having an array of images (json objects) [ { "image": [ { "_id": "5fbfdc75aea26e00484a787a", "name": "WhatsApp Image 2020-10-23 at 11.55.25 AM.jpeg", "alternativeText": "", "caption": "", "hash": "Whats_App_Image_2020_10_23_at_11_55_25_AM_773f08e059", "ext": ".jpeg", "mime": "image/jpeg", "size": 50.67, "width": 590, "height": 576, "url": "/uploads/Whats_App_Image_2020_10_23_at_11_55_25_AM_773f08e059.jpeg", "formats": { "thumbnail": { "name": "thumbnail_WhatsApp Image 2020-10-23 at 11.55.25 AM.jpeg", "hash": "thumbnail_Whats_App_Image_2020_10_23_at_11_55_25_AM_773f08e059", "ext": ".jpeg", "mime": "image/jpeg", "width": 160, "height": 156, "size": 5.97, "path": null, "url": "/uploads/thumbnail_Whats_App_Image_2020_10_23_at_11_55_25_AM_773f08e059.jpeg" }, "small": { "name": "small_WhatsApp Image 2020-10-23 at 11.55.25 AM.jpeg", "hash": "small_Whats_App_Image_2020_10_23_at_11_55_25_AM_773f08e059", "ext": ".jpeg", "mime": "image/jpeg", "width": 500, "height": 488, "size": 41.95, "path": null, "url": "/uploads/small_Whats_App_Image_2020_10_23_at_11_55_25_AM_773f08e059.jpeg" } }, "provider": "local", "related": [ "5fbfdc7eaea26e00484a787b" ], "createdAt": "2020-11-26T16:48:53.715Z", "updatedAt": "2020-11-26T16:49:02.626Z", "__v": 0, "id": "5fbfdc75aea26e00484a787a" } ], "_id": "5fbfdc7eaea26e00484a787b", "title": "I want an center table", "description": "I want a 3x3 center table with Indian marble top", "createdAt": "2020-11-26T16:49:02.619Z", "updatedAt": "2020-11-26T17:23:40.655Z", "__v": 0, "category": { "_id": "5fbfe21d0bbf020065dd0b1e", "category_name": "Furniture", "createdAt": "2020-11-26T17:13:01.743Z", "updatedAt": "2020-11-26T17:13:01.754Z", "__v": 0, "id": "5fbfe21d0bbf020065dd0b1e" }, "id": "5fbfdc7eaea26e00484a787b" }, { "image": [ { "_id": "5fc073aaf41381008738f53a", "name": "1RK-Apartment-for-Sale-in-Nalasopara-East-Mumbai-at-Sai-Krupa-Chawl-Listing-Photo_Kitchen.jpeg", "alternativeText": "", "caption": "", "hash": "1_RK_Apartment_for_Sale_in_Nalasopara_East_Mumbai_at_Sai_Krupa_Chawl_Listing_Photo_Kitchen_90475427e3", "ext": ".jpeg", "mime": "image/jpeg", "size": 12.22, "width": 300, "height": 300, "url": "/uploads/1_RK_Apartment_for_Sale_in_Nalasopara_East_Mumbai_at_Sai_Krupa_Chawl_Listing_Photo_Kitchen_90475427e3.jpeg", "formats": { "thumbnail": { "name": "thumbnail_1RK-Apartment-for-Sale-in-Nalasopara-East-Mumbai-at-Sai-Krupa-Chawl-Listing-Photo_Kitchen.jpeg", "hash": "thumbnail_1_RK_Apartment_for_Sale_in_Nalasopara_East_Mumbai_at_Sai_Krupa_Chawl_Listing_Photo_Kitchen_90475427e3", "ext": ".jpeg", "mime": "image/jpeg", "width": 156, "height": 156, "size": 6.45, "path": null, "url": "/uploads/thumbnail_1_RK_Apartment_for_Sale_in_Nalasopara_East_Mumbai_at_Sai_Krupa_Chawl_Listing_Photo_Kitchen_90475427e3.jpeg" } }, "provider": "local", "related": [ "5fc07407f41381008738f53c" ], "createdAt": "2020-11-27T03:34:02.177Z", "updatedAt": "2020-11-27T03:35:35.325Z", "__v": 0, "id": "5fc073aaf41381008738f53a" }, { "_id": "5fc073fdf41381008738f53b", "name": "images.jpeg", "alternativeText": "", "caption": "", "hash": "images_4ba1796688", "ext": ".jpeg", "mime": "image/jpeg", "size": 9.55, "width": 351, "height": 144, "url": "/uploads/images_4ba1796688.jpeg", "formats": { "thumbnail": { "name": "thumbnail_images.jpeg", "hash": "thumbnail_images_4ba1796688", "ext": ".jpeg", "mime": "image/jpeg", "width": 245, "height": 101, "size": 6.44, "path": null, "url": "/uploads/thumbnail_images_4ba1796688.jpeg" } }, "provider": "local", "related": [ "5fc07407f41381008738f53c" ], "createdAt": "2020-11-27T03:35:25.211Z", "updatedAt": "2020-11-27T03:35:35.325Z", "__v": 0, "id": "5fc073fdf41381008738f53b" } ], "_id": "5fc07407f41381008738f53c", "title": "pest control के लिए", "description": "हमारा घर 700 वर्गफुट का है", "createdAt": "2020-11-27T03:35:35.313Z", "updatedAt": "2020-11-27T03:36:20.592Z", "__v": 0, "category": { "_id": "5fc07424f41381008738f53f", "category_name": "Pest Control", "createdAt": "2020-11-27T03:36:04.739Z", "updatedAt": "2020-11-27T03:36:04.748Z", "__v": 0, "id": "5fc07424f41381008738f53f" }, "id": "5fc07407f41381008738f53c" } ] I now want to show Image URL and referring it in following manner in React Native. Following is React Native code for view <View> {isLoading ? <ActivityIndicator/> : ( <FlatList data={data} keyExtractor={({ id }, index) => id} renderItem={ renderItem } /> )} </View> and renderItem is defined as following function renderItem({ item }) { console.log(item.image[0].name); } and I get following error undefined is not an object (evaluating 'item.image[0]') Can you point where am I going wrong?
You're not reading data properly. As you're using nested JSON object so you can access data using the following approaches: For Single Image: item[0].image[0].url For all the Images: item.forEach(function(value, key) { value.image.map(image => console.log(image.url)); }); I have tried your code in react native expo snack it's working fine Expo Snack Link
angular ui tree for complex json
How to create angular ui tree for complex json? [ { "name": "bmw", "model": "x3", "specs": [ { "name": "bmw", "maxspeed": 350, "minspeed": 0, "model": "x3", "type": "car" }, { "value": 30, "name": "bmw", "maxspeed": 350, "minspeed": 0, "model": "x3", "type": "car" } ], "available": true, "price": 50 }, { "name": "audi", "model": "r8", "specs": [ { "color": [ { "value": "red", "price": 100 }, { "value": [ "white", "black" ], "price": 200 } ], "maxspeed": 330, "minspeed": 0, "type": "car" }, { "color": [ { "value": "blue", "price": 300 }, { "value": [ "yellow", "gold" ], "price": 500 } ], "maxspeed": 330, "minspeed": 0, "type": "car" } ], "available": true } ]
elasticsearch ngrams results are wrong
I am trying to implement partial matching using ngrams in elasticsearch but not getting the expected results out of it. I am following this link:- https://www.elastic.co/guide/en/elasticsearch/guide/current/_index_time_search_as_you_type.html I have done all the things which are mentioned in this link. My dataset contains 3 fields i.e id,name,age. Here is my mapping and setting of my_index GET /my_index/_settings { "my_index": { "settings": { "index": { "creation_date": "1433249154544", "uuid": "hKxHVnqaRVmji31xK92pVA", "number_of_replicas": "1", "analysis": { "filter": { "autocomplete_filter": { "type": "edge_ngram", "min_gram": "1", "max_gram": "20" } }, "analyzer": { "autocomplete": { "type": "custom", "filter": [ "lowercase", "autocomplete_filter" ], "tokenizer": "standard" } } }, "number_of_shards": "1", "version": { "created": "1040499" } } } } } GET /my_index/_mapping/my_type { "my_index": { "mappings": { "my_type": { "properties": { "#timestamp": { "type": "date", "format": "dateOptionalTime" }, "#version": { "type": "string" }, "age": { "type": "long" }, "host": { "type": "string" }, "id": { "type": "string" }, "message": { "type": "string" }, "name": { "type": "string", "index_analyzer": "autocomplete", "search_analyzer": "standard" }, "path": { "type": "string" }, "type": { "type": "string" } } } } } } My query to elastic search is :- GET /my_index/my_type/_search { "query": { "match": { "name": { "query": "raman r" } } } } According to me now the results should display only "raman ram" but it is also showing other results as well:- { "took": 13, "timed_out": false, "_shards": { "total": 1, "successful": 1, "failed": 0 }, "hits": { "total": 9, "max_score": 2.6631343, "hits": [ { "_index": "my_index", "_type": "my_type", "_id": "2", "_score": 2.6631343, "_source": { "message": [ "2,raman,23" ], "#version": "1", "#timestamp": "2015-06-02T13:07:18.041Z", "type": "my_type", "host": "shubham-VirtualBox", "path": "/home/shubham/sample.csv", "id": "2", "name": "raman", "age": 23 } }, { "_index": "my_index", "_type": "my_type", "_id": "10", "_score": 1.8003473, "_source": { "message": [ "10,raman ram,43" ], "#version": "1", "#timestamp": "2015-06-02T13:11:03.455Z", "type": "my_type", "host": "shubham-VirtualBox", "path": "/home/shubham/sample.csv", "id": "10", "name": "raman ram", "age": 43 } }, { "_index": "my_index", "_type": "my_type", "_id": "1", "_score": 0.26245093, "_source": { "message": [ "1,Ram,342" ], "#version": "1", "#timestamp": "2015-06-02T13:07:18.040Z", "type": "my_type", "host": "shubham-VirtualBox", "path": "/home/shubham/sample.csv", "id": "1", "name": "Ram", "age": 342 } }, { "_index": "my_index", "_type": "my_type", "_id": "3", "_score": 0.26245093, "_source": { "message": [ "3,ramayan,23" ], "#version": "1", "#timestamp": "2015-06-02T13:07:18.041Z", "type": "my_type", "host": "shubham-VirtualBox", "path": "/home/shubham/sample.csv", "id": "3", "name": "ramayan", "age": 23 } }, { "_index": "my_index", "_type": "my_type", "_id": "4", "_score": 0.26245093, "_source": { "message": [ "4,ramaram,231" ], "#version": "1", "#timestamp": "2015-06-02T13:07:18.041Z", "type": "my_type", "host": "shubham-VirtualBox", "path": "/home/shubham/sample.csv", "id": "4", "name": "ramaram", "age": 231 } }, { "_index": "my_index", "_type": "my_type", "_id": "5", "_score": 0.26245093, "_source": { "message": [ "5,rampy,1" ], "#version": "1", "#timestamp": "2015-06-02T13:07:18.041Z", "type": "my_type", "host": "shubham-VirtualBox", "path": "/home/shubham/sample.csv", "id": "5", "name": "rampy", "age": 1 } }, { "_index": "my_index", "_type": "my_type", "_id": "6", "_score": 0.26245093, "_source": { "message": [ "6,ration,11" ], "#version": "1", "#timestamp": "2015-06-02T13:07:18.041Z", "type": "my_type", "host": "shubham-VirtualBox", "path": "/home/shubham/sample.csv", "id": "6", "name": "ration", "age": 11 } }, { "_index": "my_index", "_type": "my_type", "_id": "7", "_score": 0.26245093, "_source": { "message": [ "7,rita,42" ], "#version": "1", "#timestamp": "2015-06-02T13:07:18.042Z", "type": "my_type", "host": "shubham-VirtualBox", "path": "/home/shubham/sample.csv", "id": "7", "name": "rita", "age": 42 } }, { "_index": "my_index", "_type": "my_type", "_id": "8", "_score": 0.26245093, "_source": { "message": [ "8,roni,45" ], "#version": "1", "#timestamp": "2015-06-02T13:07:18.050Z", "type": "my_type", "host": "shubham-VirtualBox", "path": "/home/shubham/sample.csv", "id": "8", "name": "roni", "age": 45 } } ] } }
I get correct results when i use "minimum_should_match": "100%" while querying. GET /my_index/my_type/_search { "query": { "match": { "name": { "query": "raman r", "minimum_should_match": "100%" } } } } Gave me better result although ranking is not right: { "took": 4, "timed_out": false, "_shards": { "total": 1, "successful": 1, "failed": 0 }, "hits": { "total": 2, "max_score": 2.6631343, "hits": [ { "_index": "my_index", "_type": "my_type", "_id": "2", "_score": 2.6631343, "_source": { "message": [ "2,raman,23" ], "#version": "1", "#timestamp": "2015-06-02T13:07:18.041Z", "type": "my_type", "host": "shubham-VirtualBox", "path": "/home/shubham/sample.csv", "id": "2", "name": "raman", "age": 23 } }, { "_index": "my_index", "_type": "my_type", "_id": "10", "_score": 1.8003473, "_source": { "message": [ "10,raman ram,43" ], "#version": "1", "#timestamp": "2015-06-02T13:11:03.455Z", "type": "my_type", "host": "shubham-VirtualBox", "path": "/home/shubham/sample.csv", "id": "10", "name": "raman ram", "age": 43 } } ] } } Don't know whether this approach is correct or not but do tell me if any alternative is there for this