hone icon indicating copy to clipboard operation
hone copied to clipboard

Missing schema in example

Open korderos opened this issue 5 years ago • 7 comments

Hi, Maybe I missed something but I assume some specific shemas are need for transformation, specialy with nested elements.

korderos avatar Jun 05 '20 07:06 korderos

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!

chamkank avatar Jun 05 '20 09:06 chamkank

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 :)

korderos avatar Jun 05 '20 13:06 korderos

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?

chamkank avatar Jun 06 '20 00:06 chamkank

Hi hone, I have a question. How can I define my own schema to what I want?

makbar2008 avatar Sep 16 '20 05:09 makbar2008

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.

angela-wu1116 avatar Oct 14 '20 21:10 angela-wu1116

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

robinkiplangat avatar Jan 29 '21 08:01 robinkiplangat

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.convert to convert your csv to nested json.

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.

chamkank avatar Jan 30 '21 03:01 chamkank