Comments (2)
About getting key values:
I think the only case where it would make sense to get the keys are when an object of objects work is basically working like a list like the JSONSchema example above or like this:
{
"people_by_id": {
"1": {"name": "John", "age": 21},
"2": {"name": "Bob", "age": 21},
"3": {"name": "Roger", "age": 21}
}
}
If we have a structure like this, then more likely than not we want that id
number, but we do not want to absolute paths to all objects, we want to iterate over people_by_id.
To get something like that to work we need to figure out a way to represent that in a python dict, because that is what we are using internally, then we would also need to decide on a how it should be looked up in a DataFetcher
.
Currently, our iterators makes an object with the given alias
available to the DataFetcher
. I think we would need to do something similar, but also inject the key
name into the alias
ed object. like this:
{
"people_item": {
"__key__": "1",
"name": "John",
"age": "21"
}
}
That way, the only difference internally between an iterated object and an iterated list of object would be that the former have the __key__
key with the original objects
key
as a value.
from kaiba.
About dynamically writing key names
Lets say that we needed to create that JSONSchema from the following csv:
name;type
firstname;string
lastname;string
age;int
There are 2 problems.
First is that when we create a kaiba config we create an object and give it an iterator. What will be produced from that will always be a list. But we don't want a list we want to iterate over some data and produce objects.
Second problem is that we need to be able to dynamically name these objects.
I think that these are two seperate tasks.
To be able to dynamically name an attribute or object we can reuse DataFetcher
, but probably give it a spesial name like name_fetcher
. This means that we might need to make "name"
an object with a default value and a fetched value. (things are getting a bit complicated)
To be able to iterate over some data and produce a list I think we might want to split the kaiba configs "object"
into two separate things. One called "list"
and one called "object"
. That way, adding an iterator to an object will always just create an object with named object children. And a list will be create a list of unnamed objects. The "object"
config could keep its iterator, but possibly have a spesific datafetcher to name children, which could be something like "path": ["item", "__key__"]
when iterating over object with named objects or `"path": ["item", "name"] when iterating normally over another list.
I will start working on some more specific proposals, but these are my initial ideas.
Please let me know how you feel about it @ChameleonTartu I think with this you'd be able to map to and from JsonSchema format in #157
from kaiba.
Related Issues (20)
- Move pydantic models to own folder and create kaiba basemodel
- Add more metadata to pydantic models
- update docs with new model names
- Fix docs/configuration.md
- Add keyword to iterators to reference an array root
- Add greater/less than conditions in if statements
- Add required keyword to config objects and attributes
- Add require_success to functions like casting and regex
- Make something to showcase Kaiba... dev.to, medium post?
- Aggregation on keys
- Remove Returns dependency
- Github actions stopped working
- Do I always have to have attrs to run kaiba? HOT 1
- Missing method process_as_bytes HOT 1
- Is it possible to iterate over data without a root? HOT 1
- Is it possible to use if-statement on objects, not values? HOT 1
- Clarify the interface to kaiba. HOT 1
- Can Kaiba be used as a converter from different formats such as AVRO and PROTOBUF to JSON and JSON Schema? HOT 4
- Should `casting` be applied after `default` value
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kaiba.