Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing schema in example #24

Open
korderos opened this issue Jun 5, 2020 · 7 comments
Open

Missing schema in example #24

korderos opened this issue Jun 5, 2020 · 7 comments

Comments

@korderos
Copy link

korderos commented Jun 5, 2020

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

@chamkank
Copy link
Owner

chamkank commented Jun 5, 2020

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!

@korderos
Copy link
Author

korderos commented Jun 5, 2020

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

@chamkank
Copy link
Owner

chamkank commented Jun 6, 2020

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?

@makbar2008
Copy link

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

@angela-wu1116
Copy link

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.

@robinkiplangat
Copy link

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

@chamkank
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants