Skip to main content

Recursively convert JSON including json-string to YAML

Project description

rj2y

PyPI PyPI Python Versions Downloads

This CLI tool is a simple utility to convert JSON to YAML. Especially useful when you want to convert JSON including JSON-embedded string.

{
  "iii": "{\"i\":\"{\\\"ii\\\": \\\"ii\\\"}\",\"ii\":\"ii\"}",
  "kkk": "{\"k\": \"{\\\"kk\\\": \\\"kk1\\\\nkk2\\\\nkk3\\\\n\\\"}\"}"
}
iii:
  i:
    ii: !!str ii
  ii: !!str ii
kkk:
  k:
    kk: !!str |-
      kk1
      kk2
      kk3

It may be convenient to reading server logs. Using with jq and yq is recommended.

Installation

pipx install rj2y

Usage

cat some.json | rj2y
rj2y some.json

Example

input json and output yaml

https://github.com/pollenjp/rj2y-py/blob/d237729c54be84f1dd78542bf4bd2476c7a16e3a/tests/unittest/test_main.py#L6-L39

https://github.com/pollenjp/rj2y-py/blob/d237729c54be84f1dd78542bf4bd2476c7a16e3a/tests/unittest/test_main.py#L45-L109

Using yq make it easier to read.

cat some.json | rj2y | yq
aaa: !!str AAA
bbb: !!bool true
ccc: !!int 123
ccc2: !!str 123
ddd: !!float 123.456
ddd2: !!str 123.456
eee:
  - !!str e
  - !!str ee
  - !!str eee
fff:
  f: !!str f
  ff: !!str ff
  fff: !!str fff
ggg:
  - g: !!str g
    gg: !!str gg
    ggg: !!str ggg
  - g: !!str g
    gg: !!str gg
    ggg: !!str ggg
hhh:
  h: !!str h
  hh: !!str hh
  hhh: !!str hhh
iii:
  i:
    ii: !!str ii
  ii: !!str ii
jjj: !!str |-
  jj1
  jj2
  jj3
kkk:
  k:
    kk: !!str |-
      kk1
      kk2
      kk3

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rj2y-0.1.5.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rj2y-0.1.5-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file rj2y-0.1.5.tar.gz.

File metadata

  • Download URL: rj2y-0.1.5.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for rj2y-0.1.5.tar.gz
Algorithm Hash digest
SHA256 735874df16d8bea0905426c5b40e02ace4535eea3b8157b023bcea065ff46f4d
MD5 b020a2d38c2f558d22b3ebd909329121
BLAKE2b-256 c5bb2708e0cfee885c5283cbce9db753735d5580fd696546b196d3d5a4ca1831

See more details on using hashes here.

File details

Details for the file rj2y-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: rj2y-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for rj2y-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a94f5b749685b92e355449a4378a662a36843c75314be41589c2a9075bfec385
MD5 f5dcb82ad908ae66127ac1d60e8ceec6
BLAKE2b-256 0f139831b143d3078553ea3be412cd340113fa9d3f3d6c860dc6aaa652498447

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page