Skip to content

Instantly share code, notes, and snippets.

@wongyouth
Created April 12, 2018 03:32
Show Gist options
  • Select an option

  • Save wongyouth/9c3655ff8cc537741a1d7d98a37e94a3 to your computer and use it in GitHub Desktop.

Select an option

Save wongyouth/9c3655ff8cc537741a1d7d98a37e94a3 to your computer and use it in GitHub Desktop.
convert json to csv sample
%.csv : %.json
@cat $< | $(MAKE) -s words | $(MAKE) -s csv > $@
# {
# "code": "0",
# "data": {
# "block": [
# {
# "type": "text",
# "line": [
# {
# "confidence": 1,
# "location": {
# "top_left": {
# "x": 3659,
# "y": 75
# },
# "right_bottom": {
# "x": 3860,
# "y": 150
# }
# },
# "word": [
# {
# "location": {
# "top_left": {
# "x": 3659,
# "y": 75
# },
# "right_bottom": {
# "x": 3857,
# "y": 150
# }
# },
# "content": "一"
# }
# ]
# },
words:
jq '[.data.block[]["line"][]["word"][] | {content: .content, left: .location.top_left.x, top: .location.top_left.y, width: (.location.right_bottom.x - .location.top_left.x), height: (.location.right_bottom.y - .location.top_left.y)}]'
# [
# {
# "content": "一",
# "left": 3659,
# "top": 75,
# "width": 198,
# "height": 75
# },
csv:
# jq -r '(.[0] | keys_unsorted) as $$keys | $$keys, map([.[$$keys[]]])[] | @csv'
jq -r '(.[0] | keys_unsorted) as $$keys | $$keys, map([.[]])[] | @csv'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment