File tree Expand file tree Collapse file tree 5 files changed +63
-3
lines changed
examples/cafe/plain-list-schema Expand file tree Collapse file tree 5 files changed +63
-3
lines changed Original file line number Diff line number Diff line change @@ -475,10 +475,10 @@ section.
475
475
Plain Lists (Unsupported)
476
476
-------------------------
477
477
478
- Flatten Tool doesn't support arrays of JSON values other than objects (just
479
- described in the previous section).
478
+ Flatten Tool doesn't recognise arrays of JSON values other than objects (just
479
+ described in the previous section) unless a schema is used .
480
480
481
- As a result heading names such as ``tag/0 `` and ``tag/1 `` would be ignored and an
481
+ Heading names such as ``tag/0 `` and ``tag/1 `` would be ignored and an
482
482
empty array would be put into the JSON.
483
483
484
484
Here's some example data:
@@ -494,6 +494,26 @@ And the result:
494
494
.. literalinclude :: ../examples/cafe/plain-list/expected.json
495
495
:language: json
496
496
497
+ However, an array of tags in the following format (semi-colon separated) can be handled if a schema is passed to Flatten Tool specifying the array type of the field.
498
+
499
+ .. csv-table ::
500
+ :file: ../examples/cafe/plain-list-schema/data.csv
501
+ :header-rows: 1
502
+
503
+ The schema we'll pass is:
504
+
505
+ .. literalinclude :: ../examples/cafe/plain-list-schema/tagsArraySchema.json
506
+ :language: json
507
+
508
+ And the result:
509
+
510
+ .. literalinclude :: ../examples/cafe/plain-list-schema/cmd.txt
511
+ :language: bash
512
+ .. literalinclude :: ../examples/cafe/plain-list-schema/expected.json
513
+ :language: json
514
+
515
+ Read on for more about typed fields and use of schemas.
516
+
497
517
498
518
Typed fields
499
519
============
Original file line number Diff line number Diff line change
1
+ $ flatten-tool unflatten -f=csv --root-list-path=cafe --schema=examples/cafe/plain-list-schema/tagsArraySchema.json examples/cafe/plain-list-schema/
2
+
Original file line number Diff line number Diff line change
1
+ name,tags
2
+ Healthy Cafe,health;low-cost;locally sourced food;take-out
3
+ Vegetarian Cafe,veggie
Original file line number Diff line number Diff line change
1
+ {
2
+ "cafe" : [
3
+ {
4
+ "name" : " Healthy Cafe" ,
5
+ "tags" : [
6
+ " health" ,
7
+ " low-cost" ,
8
+ " locally sourced food" ,
9
+ " take-out"
10
+ ]
11
+ },
12
+ {
13
+ "name" : " Vegetarian Cafe" ,
14
+ "tags" : [
15
+ " veggie"
16
+ ]
17
+ }
18
+ ]
19
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "$schema" : " http://json-schema.org/draft-04/schema#" ,
3
+ "type" : " object" ,
4
+ "properties" : {
5
+ "tags" : {
6
+ "items" : {
7
+ "type" : " string"
8
+ },
9
+ "type" : " array"
10
+ },
11
+ "name" : {
12
+ "type" : " string"
13
+ }
14
+ }
15
+ }
16
+
You can’t perform that action at this time.
0 commit comments