Missing schema in example
Hi, Maybe I missed something but I assume some specific shemas are need for transformation, specialy with nested elements.
You don't need a schema, hone will automatically generate one for you by looking at the column names and performing splits based on delimiting characters. The example shows that you can provide your own schema if you like, but it's entirely optional. That means you can completely remove the schema portion of the code:
As a module:
import hone
optional_arguments = {
"delimiters": [" ", "_", ","]
}
Hone = hone.Hone(**optional_arguments)
result = Hone.convert('path/to/input.csv') # nested schema is auto-generated
Or using the CLI:
hone 'path/to/input.csv' 'path/to/output.json'
Let me know if you have any further questions!
Thanks for your help. Maybe my example is bit too complex I have something like this that's describe a tree : L1 L2 L3 L4 A B B B A C D D A C E F A2 G H I .....
And I'm trying to ouput : { "name":"A", "children":[ { "name":"B", "size":1 } ], etc etc
with a child level each time. Something recursive... Do you think it could be achieve with hone ? Thanks :)
L1 L2 L3 L4
A B B B
A C D D
A C E F
A2 G H I
In your example CSV, could you clarify what each row means? Is it node child1 child2 child3?
Hi hone, I have a question. How can I define my own schema to what I want?
Hi,
I'm new to json files, and I just got my own schema.json file for the format I need. Could you advise how I can use the schema file in the command line? Also, please let me know if I should start a new issue.
Hi @angela-wu1116, did you get working with your own schema file?
I'd like some help in working with a schema I have setup cc @chamkank
Hi everyone, apologies for the late response.
If you don't want hone to generate a schema for your automatically, and want to use your own schema, here's how you would write your own schema.
For the sake of this example, let's look at the schema that hone uses to convert example_a.csv to example_a.json.
To see what schema hone automatically generates and uses for the conversion, use get_schema:
import hone
Hone = hone.Hone()
schema = Hone.get_schema('path/to/input.csv')
print(schema)
- Running this outputs the schema:
{ "adopted_since":"adopted_since", "adopted":"adopted", "birth":{ "year":"birth year", "month":"birth month", "day":"birth day" }, "weight (kg)":"weight (kg)", "age (years)":"age (years)", "name":"name" }- This is what's eventually used by
Hone.convertto convert your csv to nested json.
- This is what's eventually used by
You can modify this schema to your liking, and then pass it into the convert method when you want to convert example_a.csv to example_a.json.
import hone
Hone = hone.Hone()
# generate schema
schema = Hone.get_schema('path/to/input.csv')
# now do whatever you want to schema
...
# convert your csv to nested json using your custom schema
result = Hone.convert('path/to/input.csv', schema = schema)
Please let me know if there are any further questions.